Physics Detecting Collision Multiple Times

Physics detecting collision multiple times

You can set one BOOL value to check if is allowed contact handling(set YES at the beginning). After updating score, you can set that variable to NO, then run moveBall() to start again and at the end of moveBall() method set BOOL value to YES. I think something like that should work.

Other way would be to remove ball/or cup nodes from parent and set it to nil (and then re-recreate them). Also I don't know how much SpriteKit "likes" this way(removing nodes before physics simulation is done).

Third way would be to have Ball class with some BOOL property that indicating whether the ball should be moved to start position. Based on that value you should update the score variable/handle contacts and collisions. So after updating the score, you set BOOL value to YES and then run moveBall() and then set BOOL value to NO etc...Similar as first method I described.

Object Collision Programming (Multiple collision case)

The problem is that for a two body collision, conservation of energy and momentum are basically sufficient for determining the outcome, but for a three body problem this is no longer the case. Even if you do do what Mark and Daren suggest, and determine all colliding bodies within a timestep, it doesn't really get you anywhere, because 1) you still won't know how to move the objects after the collision; and 2) the primary question in how many objects to consider during each collision isn't the timestep but the deformation of the objects, and if you treat this correctly the sequence of updating within a timestep wont matter. For example, if you have very soft objects, they will probably be in contact for many timesteps, and very hard objects only a few timesteps.

A good answer to this problem is a bit tricky, and the reason for this is contained in your bonus question, that is, what's the mechanism. The mechanism is basically just the things you're not considering in your simplified problem: deformation of the objects, slip, rotation, etc, but these will generally be dominant issues in three body collision.

What you do depends entirely on how much accuracy you need. You could just pretend that all collisions are either between two objects, or a third hitting two is always exactly symmetric (which is a very rare event). As a more accurate start you could just consider that they are deformable objects, assume that each collision has a moment in time when everything is maximally deformed, and what are the forces that result from these deformations, and send things off based on these forces (F=dp/dt). Other approximations could be made though, say just dividing up the momentum transfer based on which one is hit first, and give this an amount proportional do (the amount of deformation)/(the distance to the next object), or some such thing.

What is the correct way of detecting collision amongst multiple objects?

You cannot just reverse the direction in which your object is moving, because the collision may happen almost from behind it, in which case the reversal will put it again in collision course against the object which collided with it. That explains the jitter that you see. You need to consider the direction from which the collision occurred, and adjust your direction vector accordingly, using the related physics formulas for what is known in physics as "elastic collisions".

Here, check this out: http://en.wikipedia.org/wiki/Elastic_collision



Related Topics



Leave a reply



Submit