Advertisement
Enjl

playerphysicspatch

Jun 7th, 2020 (edited)
2,639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.15 KB | None | 0 0
  1. local lastXSpeed = {}
  2. local ppp = {}
  3.  
  4. ppp.speedXDecelerationModifier = 0.08
  5. ppp.groundTouchingDecelerationMultiplier = 1
  6. ppp.groundNotTouchingDecelerationMultiplier = 2
  7.  
  8. ppp.accelerationMaxSpeedThereshold = 2
  9. ppp.accelerationMinSpeedThereshold = 0.1
  10. ppp.accelerationSpeedDifferenceThereshold = 0.2
  11. ppp.accelerationMultiplier = 1.5
  12.  
  13. ppp.aerialIdleDeceleration = 0.98
  14.  
  15. ppp.enabled = true
  16.  
  17. function ppp.onInitAPI()
  18.     registerEvent(ppp, "onTick")
  19. end
  20.  
  21. function ppp.onTick()-- (deceleration tightness)
  22.     if ppp.enabled then
  23.         for k,p in ipairs(Player.get()) do
  24.             lastXSpeed[k] = lastXSpeed[k] or 0
  25.             if not p:mem(0x3C, FIELD_BOOL) then
  26.                 if (not (p:isGroundTouching() and p:mem(0x12E, FIELD_BOOL))) then
  27.                     local mod = ppp.groundTouchingDecelerationMultiplier
  28.                     if (not p:isGroundTouching()) then
  29.                         mod = ppp.groundNotTouchingDecelerationMultiplier
  30.                     end
  31.                     if p.rightKeyPressing then
  32.                         if p.speedX < 0 then
  33.                             p.speedX = p.speedX + ppp.speedXDecelerationModifier * mod;
  34.                         end
  35.                     elseif p.leftKeyPressing then
  36.                         if  p.speedX > 0 then
  37.                             p.speedX = p.speedX - ppp.speedXDecelerationModifier * mod;
  38.                         end
  39.                     else
  40.                         p.speedX = p.speedX * ppp.aerialIdleDeceleration;  
  41.                     end
  42.                 end
  43.            
  44.             -- (acceleration tightness)
  45.                 local xspeeddiff = p.speedX - lastXSpeed[k]
  46.  
  47.                 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
  48.                     p.speedX = p.speedX - xspeeddiff
  49.                     p.speedX = p.speedX + xspeeddiff * ppp.accelerationMultiplier
  50.                 end
  51.  
  52.             end
  53.             lastXSpeed[k] = p.speedX
  54.         end
  55.     end
  56. end
  57.  
  58. return ppp
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement