Mutiple collision handler


I am currently developing a racing game Panda3d

but I have a problem:

My route consists of a series of square (GeomNode) and on the left and right and I have 2 CollisionPolygon and 1 CollisionSegment representing the front of a car. I use these 3 things to detect off road event(I use a CollisionHandlerEvent) this work well.

Now I add to my game physics: I put a mass for the car and I want it to stay on the road (it goes up and decent) (with a gravitational force). To do this I create a CollisionPolygon for ground and CollisionSphere (which represents the car). I then use a PhysicsCollisionHandler.but I want separate the management of the collision left/right of the road and the physics (ground).
It’s possible?

Here is a screenshot:

I want to use the CollisionSegment for detecting off road/ lane changes.

and the CollisionSphere for keep the car on the road.

but now if the CollisionSphere touch the middle CollisionPolgon the PhysicsCollisionHandler works and I don’t want this because I want to change lanes (right-left and left-right) .

thank you in advance.

good day and happy good year.

PS: Sorry for my english.

I did not explain properly?

Yes you can create multiple collision handlers.
Yes you can rewrite PhysicsCollisionHandler to suite your needs.

But i still dont get why you need a middle of the road collision barrier?

I need a middle of the road collision barrier for know where I am on the road.

But thanks my problem is solved.
I used the setCollideMask and is Ok!

Bye bye.

I have again a problem:

I want to know on which sqare the car is. It is possible to query the CollisionTraverser(or the PhysicsCollisionHandler) to know which square is colliding with the CollisionShpere (representing the car)?

I know the CollisionHandlerQueue store a queue of the current colliding node. The PhysicsCollisionHandler do the same job?

thank in advance.

Good day.

The PhysicsCollisionHandler does not store a queue. But it does trigger events whenever you start or stop colliding with a surface; and you can listen for those events and keep track of the current set of colliding objects yourself.


Ok thank you.

How I listen the events. With a code like this ?:


this code does not work.


See the manual page entitled “Collision Handlers”, specifically the bit about CollisionHandlerEvent, for specifics about triggering events. Note that PhysicsCollisionHandler inherits from CollisonHandlerEvent, so it picks up all of this functionality. You may also find it helpful to use messenger.toggleVerbose() to enable reporting of all events generated, if you can’t find your collision event.


Thank you very much drwr. I have solve my problem :slight_smile: