# Multiple Collisions

Hi Folks,

How to deal with multiple collisions on the same from object?

Given:
a box made out of collision planes and a sphere enclosed within the box. The sphere can be moved by joystick but the collision system starts to brake the sphere’s movment to keep it from hitting a wall

this works fine as long as it colides with a single wall but when boxed into an edge or corner after a little bit of uncontroled bouncing it leaves the box.

I persume to solve this issue I have to acess the individual events sent by the collision traverser. but how do I do that?

Do I have to switch to collisionhanderQueue?

cheers
Martin

I suggest one of three choices:

(1) Actually model your box out of CollisionPlanes, instead of using CollisionPolygons as you must be doing now. CollisionPlanes cannot be escaped, no matter how much bouncing you do. This only works if you never want to be outside the box, of course; or if you can determine reliably when you are supposed to be allowed outside of the box.

(2) Avoid acute corners in your box. As long as your corners are >= 90 degrees each, you should have relatively little trouble. If you are indeed bouncing out of a rectilinear box, something bigger might be wrong.

(3) Use CollisionHandlerFluidPusher instead of CollisionHandlerPusher. This is a somewhat experimental object that does a better job of handling acute corners.

David

Hi David,

ad2) Hard to do but I’ll give it a Go and but some chamfers in place

ad3) I’m not sure if pushers are the right thing to use:

The Ball is a representation of a physical object which has to be kept from colliding with the box and other impediments but can only take a certain amount of acceleration; everything has to be quite smooth.

My approach now: The ball is now controlled by Joystick ( JInput (x,y,z) )and in dependency of the given acceleration and the momentary speed a collision sphere is offset from the physical object ( Vec(direction of travel), length(Braking distance) ) once the collission sphere collides with an impediment JInput(x,y,z) is modified to:

JInput(x,y,z) = JInput(x,y,z) - ( collisionSurfaceNormal(x,y,z) projected on JInput(x,y,z))

this takes care of the velocity component that would let the object fly into the impediment and let it slide along the wall this works fine ( OK, while sliding along the wall there are still some oscillations I have to get rid off) but when I steer the ball into a corner and it starts getting a second collision the object flees the box after a couple of bounces.

In the messenger I see that two events are thrown and my feeling tells me that I have to react on both of them but at the moment I have no clue how to do that. In the collisionHandlerEvent there is a method getNumAgainPatterns but will that help and if how?

thanks

Martin

Oh, you’re implementing the reaction to the wall yourself? Right, if you do that, you will have to handle collisions with multiple walls yourself as well. This can get very complicated in the general case.

The CollisionHandlerEvent won’t really be much help. You can use CollisionHandlerQueue and examine the set of collisions every frame the hard way. But if you write all this low-level code in Python, you will be inviting a performance issue.

Why not use a pusher? This is exactly the work that a pusher does. It’s already implemented for you, and it’s implemented in C++, where it’s much faster than anything you could write in Python.

David

Sorry to hijack a little… but when I used the CollisionHandlerFluidPusher instead of just the normal CollisionHandlerPusher; I seem to break it when I call for it to do a quick collision check with base.cTrav.traverse(render) ^^:

``````Error-> Error ['Traceback (most recent call last):\n', '  File "backup.py", line 2780, in
<module>\n    run()\n', '  File "C:\\Panda3D-1.6.2\\direct\\showbase\\ShowBase.py", line 2
ew.py", line 429, in step\n    self.mgr.poll()\n', '  File "backup.py", line 2765, in move
\n    base.cTrav.traverse(render)\n', 'AssertionError: false at line 112 of c:\\p\\p3d\\pa
nda3d-1.6.2\\panda\\src\\collide\\collisionHandlerFluidPusher.cxx\n']``````

If you look a little bit back in the log, you should also see the error message:

which should tell you that you need to call pusher.setHorizontal(True), and don’t expect it to move your object in the Z axis.

This limitation, and some other bugs, have been removed in the current cvs revision of this code (which will be part of the 1.7 release).

David

For a quick hack, why not make 4 invisible diagonal walls at the cube’s corners? That way you’ll still be dealing with one collision only.

Hi David,

it’s solved!

but let me extemporate a little.

my object controled by an velocity input signal aproaches a wall. A Collision Sphere offset from the object by the braking distance collides with the wall – now the velocity input is reduced by deltaT multipied by it’s maximum Deceleration this new velocity input is then integrated to update my new position so my object never hits the wall but gets smoothly stoped.
In the event of driving the thingy into an edge or a corner panda is fireing events for all of them and they also get processed nicely. My error was that I forgot to sum all those correction vectors before applying them to the input signal.
I’m still not sure if that could have been accomplished by a pusher…the pusher would have kept my collision sphere out of the wall but how would I have been able to get feedback to modulate the input signal.

But having solved this I’m still stuck on an other: