I need help with making a collision resolver
Posted: Mon Nov 23, 2020 3:16 pm
Hey! I am new to LOVE and just started making a 2D platformer game.
I have already successfully written a function to determine whether two game objects are colliding:
with pos and size being Vector2
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
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