"panda3d.core is not a package"?


#1

I’m trying to set up a simple player character on top of a terrain object. I tried to reparent the camera to the player Actor in order to get the camera to follow it:

def LoadPlayer(self):

	player = DW_Dplayer.DragonPlayer()
	base.camera.reparentTo(player)

and got this error:

NodePath.reparent_to() argument 1 must be panda3d.core.NodePath, not DragonPlayer

Which means I need my class to inherit from the NodePath class:

import panda3d

from direct.actor.Actor import Actor
from panda3d.core.NodePath import NodePath

class DragonPlayer(NodePath):

    def __init__(self):

	    self.actor = Actor('low_poly_dragon.egg',{
		    'Idle':'low_poly_dragon-Idle.egg',
		    'Walk':'low_poly_dragon-Walk.egg',
		    'Run':'low_poly_dragon-Run.egg',
		    'Sprint':'low_poly_dragon-Sprint.egg',
		    'Flap':'low_poly_dragon-Flap.egg'})


	    self.actor.setPos(100,100,200)
	    self.actor.reparentTo(render)

which leads to this:

No module named ‘panda3d.core.PandaNode’; ‘panda3d.core’ is not a package

I need a guiding hand because I obviously have no idea what I’m doing XP


#2

The correct code is:

from panda3d.core import NodePath

#3

Thank you! That leaves me with my original problem however, how do I inherit from nodepath for a class:

import panda3d

from direct.actor.Actor import Actor
from panda3d.core import NodePath

class DragonPlayer(NodePath):

    def __init__(self):

	    self.actor = Actor('low_poly_dragon.egg',{
		    'Idle':'low_poly_dragon-Idle.egg',
		    'Walk':'low_poly_dragon-Walk.egg',
		    'Run':'low_poly_dragon-Run.egg',
		    'Sprint':'low_poly_dragon-Sprint.egg',
		    'Flap':'low_poly_dragon-Flap.egg'})


	    self.actor.setPos(100,100,200)
	    self.actor.reparentTo(render)

so I don’t get this:

NodePath.reparent_to() argument 1 must be panda3d.core.NodePath, not DragonPlayer


#4

I would advise against inheriting from NodePath. NodePath is a C++ class, which has some oddities when subclassing in Python. Since your class already has an Actor, I would reccomend you reparent the camera to that actor:

base.camera.reparentTo(player.actor)

This manual page goes into more detail: https://www.panda3d.org/manual/index.php/Subclassing


#5

For what it’s worth, the step you were missing was to upcall to the base class in the constructor:

    def __init__(self):
        NodePath.__init__(self, "name of node")

But, this is a bad idea, as Moguri points out. It’s better to use composition instead of inheritance.


#6

Thank you! That is very good to know.