Enjl

playerphysicspatch

Jun 7th, 2020 (edited)
348
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. function ppp.onInitAPI()
  14.     registerEvent(ppp, "onTick")
  15. end
  16.  
  17. function ppp.onTick()-- (deceleration tightness)
  18.     for k,p in ipairs(Player.get()) do
  19.         lastXSpeed[k] = lastXSpeed[k] or 0
  20.         if (not (p:isGroundTouching() and p:mem(0x12E, FIELD_BOOL))) then
  21.             local mod = ppp.groundTouchingDecelerationMultiplier
  22.             if not p:isGroundTouching() then
  23.                 mod = ppp.groundNotTouchingDecelerationMultiplier
  24.             end
  25.             if p.rightKeyPressing then
  26.                 if p.speedX < 0 then
  27.                     p.speedX = p.speedX + ppp.speedXDecelerationModifier * mod;
  28.                 end
  29.             elseif p.leftKeyPressing then
  30.                 if  p.speedX > 0 then
  31.                     p.speedX = p.speedX - ppp.speedXDecelerationModifier * mod;
  32.                 end
  33.             else
  34.                 p.speedX = p.speedX * 0.98;
  35.             end
  36.         end
  37.        
  38.         -- (acceleration tightness)
  39.         local xspeeddiff = p.speedX - lastXSpeed[k]
  40.  
  41.         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
  42.             p.speedX = p.speedX - xspeeddiff
  43.             p.speedX = p.speedX + xspeeddiff * ppp.accelerationMultiplier
  44.         end
  45.  
  46.         lastXSpeed[k] = p.speedX
  47.     end
  48. end
  49.  
  50. return ppp
RAW Paste Data