I'm working on a new level.
It has gravity and Infected AI.
My problem is that I want the asteroids to bounce off each other, instead of passing straight through one another.
This problem is twofold:1)
I need a collision engine to detect when asteroids have collided, and which two asteroids were involved in the collision.2)
Then I need to decide how the asteroids will bounce. To do that, I need to modify the MomentumX
values for those asteroids in a way that is appropriate to the force, relative size, and direction that each roid is travelling in, as well as the angle at which they strike one another.
I am pleased to say that I have part 1 totally sorted.
I use pythagoras to work out the distance between the centres of both asteroids. Then, if that distance is less than Asteroid 1 Radius + Asteroid 2 Radius, they have collided.
This code works fine.
For part 2, I am struggling.
I am having real difficulty figuring out the formal rules of collision here, and how I express what happens when say, 2 billiard balls collide, in LUA.
I've no clue what sort of equations I should be modelling, or any of the maths that is involved.
Here's a diagram showing the limitations of my current understanding.
For my examples, I assume all objects are of the same size, density, and elasticity/bounciness - though I will also need to gain an understanding of the role these parameters play.
Help with this would be very much appreciated.