I have two moving objects. The objects consist of a velocity vector2
, a Rectangle
and a vector2
as position (origin in the middle of the rect).
Some rough pseudo code for my collision checking function:
foreach (object1 in objects)
foreach (object2 in objects)
intersectionRect = Rectangle.Intersect(object1.Rectangle, object2.Rectangle)
if (intersectionRect != Rectangle.Empty) // If colliding
ResolveCollision(object1, object2, intersectionRect) // does nothing currently
object1.position += object1.velocity
object2.position += object2.velocity
My problem now is how to do the collision resolution. I need help figuring out a formula to calculate the new velocities of the objects so that they only move as far as they need to not intersect anymore.
I have used google to find a solution, but the most stuff I found was how to do collisions and not how to resolve them.