In my game, I have implemented a class, called Kid, for characters which loads their model and puts a collision sphere around them. I also made a class called MouseRay which creates a collision ray, a traverser, a handler, and so forth to use for mouse picking.
In the MouseRay class, I have a function to use for performing the actual collision checking. It looks like this:
def collisionTest(self, testNode):
#This function takes a base node and checks that node and it's children for collision with the mouse ray. It also makes
#sure that the ray is positioned correctly and aimed at the mouse pointer.
if base.mouseWatcherNode.hasMouse():
#We must check to make sure the window has the mouse to prevent a crash error caused by accessing the mouse
#when it's not in the window.
mpos = base.mouseWatcherNode.getMouse()
#get the mouse position in the window
self.collideRay.setFromLens(base.camNode, mpos.getX(), mpos.getY())
#sets the ray's origin at the camera and directs it to shoot through the mouse cursor
self.collideTraverser.traverse(testNode)
#performs the collision checking pass
return
When I pass a Kid object into this collision function to be tested, I receive the error “.traverse() argument 1 must be nodepath, not instance”
The end goal is to have many Kids passed into this function at once as children of a dummy node. Currently, the Kid class doesn’t derive from any existing classes. Should I make the Kid class inherit from the NodePath class, or some other class, so I can reparent them to a dummy node?