Skip to content

Instantly share code, notes, and snippets.

@The0x539
Created March 5, 2018 23:16
Show Gist options
  • Save The0x539/43caf5c07fdac0ccbc8f58eb316eece3 to your computer and use it in GitHub Desktop.
Save The0x539/43caf5c07fdac0ccbc8f58eb316eece3 to your computer and use it in GitHub Desktop.
SMBX deceleration logic
if player.speedX ~= 0 then
local direction = (player.speedX > 0 and 1 or -1)
local amt = 0
local fwd, back = player.rightKeyPressing, player.leftKeyPressing
if direction < 0 then
fwd, back = back, fwd
end
local run = player.runKeyPressing
local gnd = player:isGroundTouching()
local fast = (math.abs(player.speedX) > Defines.player_walkspeed + 0.00001)
if gnd and player.downKeyPressing then
fwd, back = false, false
end
if gnd and not fwd then
amt = amt + 0.07
end
if fast and not run then
amt = amt + 0.1
end
if back then
amt = amt + 0.21
if not gnd then
amt = amt + 0.07
end
end
player.speedX = player.speedX + direction * amt
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment