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.