Sliding/Acceleration/Skidding in Love2D?

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
User avatar
JacKobOriginal
Prole
Posts: 11
Joined: Thu Mar 22, 2018 12:05 am
Location: Colombia
Contact:

Sliding/Acceleration/Skidding in Love2D?

Post by JacKobOriginal »

I'm currently making a mario fangame and I wanted to know how would an acceleration/sliding movement work in Love2D.
Anything about Skidding would also be grateful.
Follow my GameDev Twitter: https://twitter.com/qqnutgames
Play Lil Jingle: https://qqnut.itch.io/lil-jingle
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Sliding/Acceleration/Skidding in Love2D?

Post by ivan »

Skidding as in Super Mario is where the player's velocity points one way, but there is a constant acceleration in the opposite direction.
In many games your velocity drops to 0 as soon as you release the movement keys.
There are other games where you could be skidding but it's not shown explicitly on the screen.
The clever thing about Mario is that they were smart enough to draw a sprite that makes Mario look like he is actually skidding.

Code: Select all

-- movement
acceleration = 0
if love.keyboard.isDown('left') then
  acceleration = -1
elseif love.keyboard.isDown('right') then
  acceleration = 1
end
-- simulation
velocity = velocity + acceleration
position = position + velocity
-- skidding check
if velocity < 0 and acceleration > 0 or velocity > 0 and acceleration < 0 then
  -- yep
end
This is similar to throwing a ball up in the air.
When you throw the ball up you make its velocity positive.
But gravity is constantly accelerating it down.
Over a few seconds, the ball's velocity goes from positive to negative.

Sliding is more complicated and is related to friction.
This is where you push an object and it eventually comes to a halt.
So when you release the movement keys, Mario slows down and stops.
Friction happens when two bodies are contacting
although some people use "damping" to emulate this effect.
User avatar
AdamRatai
Prole
Posts: 1
Joined: Tue Jan 21, 2020 8:32 am

Re: Sliding/Acceleration/Skidding in Love2D?

Post by AdamRatai »

Thank you! Works like a charm :).
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 4 guests