Trying to make platformer from scratch, how do I keep my player falling when it collides on the side?
Posted: Mon Jul 24, 2023 7:32 pm
I didn't like bump.lua because it was a little bit complicated for me so I decided to make my own collision system from scratch. The play stops when it hits the platform but it stays at that y level, so it can't fall off the ledge. And when the player falls and hits the side of the ledge, it clips onto the top of the platform. I am aware of the issue but I am having trouble trying to find a solution.
Here is my algorithm for the move function
The "collide" function returns true anytime the player (rectA) collides with the platform (rectB) from any direction.
Here is my algorithm for the move function
Code: Select all
function move(dt)
if not collide(rectA, rectB) or (rectA.x == rectB.x - rectA.w) then -- supposed to prevent player from stopping when colliding on the sides
rectA.y = rectA.y + rectA.yVel*dt -- accelerated player downward with the force of gravity
rectA.yVel = rectA.yVel - rectA.gravity*dt
else
rectA.gravity = 0 -- player lands vertically on platform it is soppoed to stop
rectA.yVel = 0
rectA.y = rectB.y - rectA.h
end
if love.keyboard.isScancodeDown("a") then
rectA.x = rectA.x - rectA.s*dt
end
if love.keyboard.isScancodeDown("d") then
rectA.x = rectA.x + rectA.s*dt
end
end