Collision solids on instances

Hi to all; I’ve been travelling a lot these past few weeks hence my absence.

I have a few models that I load and then instance later on; the models have collision solids within them that are meant to be used as INTO collision objects. I’m using procedurally generated terrains and then to fill up the terrains I instance the loaded models onto the newly generated terrain.

For the collision FROM object as I am at the testing phase of my project I simply use ralph and wrap a collision sphere around him like so:

ralph = Actor("samples/Roaming-Ralph/models/ralph",
                {"run":"samples/Roaming-Ralph/models/ralph-run",
                "walk":"samples/Roaming-Ralph/models/ralph-walk"})
ralph.reparentTo(render)
anp = ralph.attachNewNode(ActorNode('actor'))
cs = CollisionSphere(ralph.getBounds().getCenter(), ralph.getBounds().getRadius())
cnodePath = anp.attachNewNode(CollisionNode('cnode'))
cnodePath.node().addSolid(cs)
pusher=PhysicsCollisionHandler()
pusher.addCollider(cnodePath, anp)
travz=CollisionTraverser()
travz.addCollider(cnodePath, pusher)
cnodePath.show()

That should be all it takes for collisions to occur right? But no collisions are occurring. The screenshot below shows: a->the collision sphere around ralph and b->the collision sphere around the instanced model. So it appears that all the collision solids are being properly loaded and parented to their respective nodepaths; but nonetheless no collisions are occurring. What am I doing wrong?


Thanks in advance.

Well, firstly, the second argument to pusher.addCollider is the node that will be pushed when a collision happens. In your case, you are passing a node that is attached to the ralph model. This means that when a collision happens, the child node of ralph will get moved around, but not ralph itself. Perhaps you should try to pass in “ralph” itself, or perhaps a node that is a parent of the ralph model. I can’t say I’m too familiar with PhysicsCollisionHandler though.

Secondly, does your terrain have collision geometry?

Hi rdb;

Performing your suggestion regarding the collision issue and passing ralph as the second argument yields this error:

Assertion failed: target.node()->is_of_type(ActorNode::get_class_type()) at line
 212 of c:\buildslave\release_sdk_win32\build\panda3d\panda\src\physics\physicsC
ollisionHandler.cxx
Assertion failed: validate_target(target) at line 117 of c:\buildslave\release_s
dk_win32\build\panda3d\panda\src\collide\collisionHandlerPhysical.cxx
Traceback (most recent call last):
  File "game_simulator.py", line 684, in <module>
    pusher.addCollider(cnodePath, ralph)
AssertionError: target.node()->is_of_type(ActorNode::get_class_type()) at line 2
12 of c:\buildslave\release_sdk_win32\build\panda3d\panda\src\physics\physicsCol
lisionHandler.cxx

Next; even though the node is attached to ralph shouldn’t a collision occur on it? But none occurs. Changing to “CollisionHandlerPusher” still gives the same result; no collision occurs:

ralph = Actor("samples/Roaming-Ralph/models/ralph",
                {"run":"samples/Roaming-Ralph/models/ralph-run",
                "walk":"samples/Roaming-Ralph/models/ralph-walk"})
ralph.reparentTo(render)
cs = CollisionSphere(ralph.getBounds().getCenter(), ralph.getBounds().getRadius())
cnodePath = ralph.attachNewNode(CollisionNode('cnode'))
cnodePath.node().addSolid(cs)
pusher=CollisionHandlerPusher()
pusher.addCollider(cnodePath, ralph)
travz=CollisionTraverser()
travz.addCollider(cnodePath, pusher)
cnodePath.show()


As you can see from the above image the collision solids parented to ralph and the instance of the boulder model intersect. Could the error be connected to instancing? To instance the boulder model this is what I do:

#load the model:
rock_boulder_l=loader.loadModel("world_resources/rock_boulder_l.egg")
rock_boulder_l.reparentTo(render)
rock_col=rock_boulder_l.find("**/rock_boulder_l_collide")
rock_col.show()

#... instance it later on when necessary:
new_np=render.attachNewNode('dum_res')
resource_refs[resource_biomes[indx_res+1][rand_sel]].show()
resource_refs[resource_biomes[indx_res+1][rand_sel]].copyTo(new_np)
resource_refs[resource_biomes[indx_res+1][rand_sel]].hide()
new_np.show()

#note->the boulder was added to a list that will be referenced whenever the player enters a biome that it [the boulder] belongs to; so the above obtains the model
#from the list using its index therein.

As for the terrain no it does not have collision geometry; I am using the GeoMipMap method to generate procedural terrains so I just use the “getElevation()” method to position the various models/actors at their respective heights within the terrain given their x and y coordinates.

Sometimes I’m such an idiot :blush: …turns out I forgot to do this:

base.cTrav=travz

Right after I created the traverser. Adding that line solved everything.