Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Playerphysicspatch SHMOOVE Mode
- -- Use with caution around slopes
- local lastXSpeed = {}
- local ppp = {}
- ppp.speedXDecelerationModifier = 0.08
- ppp.groundTouchingDecelerationMultiplier = 1
- ppp.groundNotTouchingDecelerationMultiplier = 2
- ppp.accelerationMaxSpeedThereshold = 2
- ppp.accelerationMinSpeedThereshold = 0.1
- ppp.accelerationSpeedDifferenceThereshold = 0.2
- ppp.accelerationMultiplier = 1.5
- ppp.aerialIdleDeceleration = 1
- ppp.lenientPSpeed = false
- ppp.enabled = true
- local RUNSPEED = 6
- local WALKSPEED = 3
- local pSpeedTimer = 0
- local pSpeedDecay = false
- function ppp.onInitAPI()
- registerEvent(ppp, "onTick")
- registerEvent(ppp, "onTickEnd")
- end
- function ppp.setWalkSpeed(spd)
- WALKSPEED = spd or 3
- end
- function ppp.setRunSpeed(spd)
- RUNSPEED = spd or 6
- end
- function ppp.onTickEnd()
- Defines.player_walkspeed = 16
- Defines.player_runspeed = 16
- for k,p in ipairs(Player.get()) do
- local maxspeed = WALKSPEED
- if p.keys.run then maxspeed = RUNSPEED end
- if p.hasStarman then
- maxspeed = maxspeed + 2.5
- end
- local sliding = false
- if p:mem(0x3C, FIELD_BOOL) then
- sliding = true
- end
- if sliding then
- sliding = false
- local slopeIdx = p:mem(0x48, FIELD_WORD)
- if p.speedY > 0 and slopeIdx > 0 then
- local b = Block(slopeIdx)
- if Block.config[b.id].floorslope ~= 0 then
- p.speedX = p.speedX + 0.1 * Block.config[b.id].floorslope
- sliding = true
- end
- end
- end
- if not sliding then -- Prevents speed decrease when not pressing any buttons
- local decrease = 0.15
- if not p:isOnGround() and not p.keys.left and not p.keys.right then
- decrease = 0
- end
- if p.speedX > maxspeed then
- p.speedX = math.max(p.speedX - decrease, maxspeed)
- elseif p.speedX < -maxspeed then
- p.speedX = math.min(p.speedX + decrease, -maxspeed)
- end
- end
- if not player:mem(0x16E, FIELD_BOOL) then
- if math.abs(p.speedX) >= RUNSPEED then
- if p:isOnGround() then
- pSpeedTimer = pSpeedTimer + 1
- else
- pSpeedTimer = pSpeedTimer - 3
- end
- else
- if pSpeedDecay then
- pSpeedTimer = 0
- end
- pSpeedTimer = pSpeedTimer - 3
- end
- pSpeedDecay = false
- pSpeedTimer = math.max(pSpeedTimer, 0)
- elseif not ppp.lenientPSpeed then
- pSpeedDecay = true
- end
- p:mem(0x168, FIELD_FLOAT, pSpeedTimer)
- local t = p:mem(0x118, FIELD_FLOAT)
- p:mem(0x118, FIELD_FLOAT, t + math.max(0, (math.abs(p.speedX) - WALKSPEED) * 0.17))
- end
- end
- function ppp.onTick()-- (deceleration tightness)
- if ppp.enabled and player.forcedState == 0 then
- for k,p in ipairs(Player.get()) do
- lastXSpeed[k] = lastXSpeed[k] or 0
- if not p:mem(0x3C, FIELD_BOOL) then
- if (not (p:isGroundTouching() and p:mem(0x12E, FIELD_BOOL))) then
- local mod = ppp.groundTouchingDecelerationMultiplier
- if (not p:isGroundTouching()) then
- mod = ppp.groundNotTouchingDecelerationMultiplier
- end
- if p.rightKeyPressing then
- if p.speedX < 0 then
- p.speedX = p.speedX + ppp.speedXDecelerationModifier * mod;
- end
- elseif p.leftKeyPressing then
- if p.speedX > 0 then
- p.speedX = p.speedX - ppp.speedXDecelerationModifier * mod;
- end
- else
- p.speedX = p.speedX * ppp.aerialIdleDeceleration;
- end
- end
- -- (acceleration tightness)
- local xspeeddiff = p.speedX - lastXSpeed[k]
- if math.abs(p.speedX) < ppp.accelerationMaxSpeedThereshold and math.abs(p.speedX) > ppp.accelerationMinSpeedThereshold and math.sign(p.speedX * xspeeddiff) == 1 and math.abs(xspeeddiff) <= ppp.accelerationSpeedDifferenceThereshold then
- p.speedX = p.speedX - xspeeddiff
- p.speedX = p.speedX + xspeeddiff * ppp.accelerationMultiplier
- end
- end
- lastXSpeed[k] = p.speedX
- end
- end
- end
- return ppp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement