Remove NodePath on Collision?

Return to Scripting Issues

Remove NodePath on Collision?

Postby The_Sandman » Mon Sep 26, 2005 6:42 am

Hello, decided to have a play with collisions and it seems straightforward but for some reason I cant get the following to sink in.

I am creating a list of model NodePaths and having them move around the screen. I created a CollisionHandlerQueue plus a CollisionTraverser and added the objects to them. On checking the queue they are generating the event needed.

I then get the NodePath and want to remove it from the scene.
Code: Select all
entry = self.collisionQueue.getEntry(i)
objectNodePath = entry.getIntoNodePath()
objectNodePath.remove()


But when I then call my class that updates the positions of the objects, the NodePath is still active. Is it possible to call something on the objectNodePath in the checking events loop that will remove it from the sceneGraph so the NodePath reports as Empty() or something similiar?

Thanks in advance.
The_Sandman
 
Posts: 131
Joined: Sun Jun 05, 2005 2:18 pm

Postby drwr » Mon Sep 26, 2005 9:51 am

You are removing the NodePath that contains the CollisionNode, which is probably not the one you wanted to remove. Presumably you wanted to remove the object itself, which I assume is a parent of the CollisionNode.

The easiest way to get a handle back to the object is to use the tag system and set a tag on your object node when you create it:
Code: Select all
myObject.setTag('object', '1')

The value of the tag doesn't matter in this case, just the fact that it has a tag with a particular key. Then when you get the collision event back, use the findNetTag() method to return the parent with the indicated key:
Code: Select all
entry = self.collisionQueue.getEntry(i)
objectNodePath = entry.getIntoNodePath().findNetTag('object')
objectNodePath.removeNode()


David
drwr
 
Posts: 11253
Joined: Fri Feb 13, 2004 12:42 pm
Location: Glendale, CA

Postby The_Sandman » Mon Sep 26, 2005 3:58 pm

Thanks for the info David. I was confusing the model nodepath with the collision nodepath :oops:

I did think about using tags. I try with a naming convention and see how that pans out.

Once again, thanks for the info.
The_Sandman
 
Posts: 131
Joined: Sun Jun 05, 2005 2:18 pm


Return to Scripting Issues

Who is online

Users browsing this forum: ninth and 1 guest