Trying to make platformer from scratch, how do I keep my player falling when it collides on the side?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
MaxGamz
Party member
Posts: 104
Joined: Fri Oct 28, 2022 3:09 am

Trying to make platformer from scratch, how do I keep my player falling when it collides on the side?

Post by MaxGamz »

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

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
The "collide" function returns true anytime the player (rectA) collides with the platform (rectB) from any direction.
zingo
Citizen
Posts: 50
Joined: Mon Jan 16, 2023 7:34 am

Re: Trying to make platformer from scratch, how do I keep my player falling when it collides on the side?

Post by zingo »

Personally, I'm going to use "box2d" for my physics because it's already available in Love2d and does most of the work. However, for a nice tutorial on getting started with a simple platformer, you could check out https://sheepolution.com/learn/book/24 and maybe get some ideas. Also, attached is an example for some basic physics using box2d and bitmap collisions. Sorry I couldn't be more helpful, maybe someone else will have a better idea of how to address the issue with your code.
Attachments
Basic_Physics.love
(6.66 KiB) Downloaded 54 times
MaxGamz
Party member
Posts: 104
Joined: Fri Oct 28, 2022 3:09 am

Re: Trying to make platformer from scratch, how do I keep my player falling when it collides on the side?

Post by MaxGamz »

zingo wrote: Mon Jul 24, 2023 10:03 pm Personally, I'm going to use "box2d" for my physics because it's already available in Love2d and does most of the work. However, for a nice tutorial on getting started with a simple platformer, you could check out https://sheepolution.com/learn/book/24 and maybe get some ideas. Also, attached is an example for some basic physics using box2d and bitmap collisions. Sorry I couldn't be more helpful, maybe someone else will have a better idea of how to address the issue with your code.
Thanks for the tip! Anything helps honestly, I'm just trying to see my options
User avatar
darkfrei
Party member
Posts: 1186
Joined: Sat Feb 08, 2020 11:09 pm

Re: Trying to make platformer from scratch, how do I keep my player falling when it collides on the side?

Post by darkfrei »

You can use 4 collision points as up, left, down, right.
So if you have collision with left or right point then stop the horizontal velocity, is with top or bottom points then stop the vertical velocity.

See code with this colliding physics here:
https://darkfrei.itch.io/connection-looper
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
Post Reply

Who is online

Users browsing this forum: mrmorr and 2 guests