I'm making a small game where things can fly around and collide. Things like boxes and so on. For each object, I have an array of all forces acting upon it, I have it's mass, it's position and it's velocity in both directions (a 2D vector). I know how to detect collision between them, but I just don't know how to react.
I used to calculate their orientation towards each other, it they were on top one another, I would just negate their y speed (v.y = -v.y
), and if they were next to each other on the x axis I would negate their x speed (v.x = -v.x
).
Now, this isn't very realistic, so, how do I do it? All objects are rectangles represented by [x, y, w, h]
vectors.
Objects can't rotate.