How to delay collision processing (SOLVED)


Suppose I have a collision between two different sprites, A and B. The two are somehow “different”. I do not mean visually but have attributes that give them special characteristics. For arguments sake let us say that they both have a “weight” with B being heavier than A (the actual criteria I want to use are rather more complex but the principle remains the same)

In my own case when the two collide I want to change their linear velocities. However, the way in which the velocities of A (lighter particle) changes depends on the way the velocities of B (heavier particle) change.

What is not clear to me is this - from what I can see both A and B get the collision_response message , and so it should be. What I need to do is to be sure that the collision response for A (lighter) is handled AFTER I have successfully created the collision response for B (heavier). How do I go about doing this in a foolproof way?

From what I can see whether A gets the message first or B is haphazard. If each goes about processing its messages entirely oblivious of the other than I cannot ensure the response pattern I am after.



The order of which the messages come is up to the physics engine.
Since each message also provides info about the other object, you should be able to filter the messages like so:

Some pseudo code:

if get_mass( < get_mass(message.other_id) then
-- now we know we only handle the collision once
-- and that the mass of `id` is larger than `other_id`



1 Like