Collision detection.

Alright, so i got a playable character. But i’m wondering, how do I detect when my player is colliding with a collision?

collision = CollisionSphere(0, 0, 3, 4)
cfloc = toon1part1.attachNewNode(CollisionNode(‘cnode’))

You should look into the CollisionTraverser: you’ll need to use the methods:

  • add_solid
    To specify which CollisionSolid (such as your CollisionSphere) is going to be used for the collision test.

  • traverse
    To specify where does the collision check happen (you can path the render node if you want to have it run on the whole scene)

  • sort_entries
    Optional, but very useful, it’ll sort the collisions detected in order of which is the closest to your solid to which is the farthest.

  • get_num_entry
    returns the number of collision detected

  • get_entry
    returns the detail for a collision (plenty of useful stuff like the exact point of the collision)

  • get_entry(x).get_into_node_path
    returns the NodePath on which a given collision happened