I have already successfully written a function to determine whether two game objects are colliding:
Code: Select all
function collision(obj1,obj2)
return (obj1.pos - obj2.pos):magnitude() < ((obj1.size*0.5)+(obj2.size*0.5)):magnitude()
end
function Vector2:magnitude()
return math.sqrt((self.x^2 + self.y^2))
end
Now I'm having a hard time trying to figure out how to calculate the vector that I need to add to the player character in order to push him out of solid objects, so that I can build walls and platforms.
What I basically need is the vector describing the rectangle created by two overlapping rectangles. I've been sitting at this for an hour getting reminded how much I suck at linear algebra.
I'd be very grateful if someone could give me an equation or help me in any way