Skip to content

Instantly share code, notes, and snippets.

@MaximumADHD
Created September 2, 2019 22:18
Show Gist options
  • Save MaximumADHD/060febddd510d32426739a94e1eed234 to your computer and use it in GitHub Desktop.
Save MaximumADHD/060febddd510d32426739a94e1eed234 to your computer and use it in GitHub Desktop.
local RunService = game:GetService("RunService")
local char = script.Parent
local humanoid = char:WaitForChild("Humanoid")
local rootPart = humanoid.RootPart
local XZ_VECTOR3 = Vector3.new(1, 0, 1)
local lastCF = CFrame.new()
local airAccel = 0
local function stepPhysics()
local state = humanoid:GetState()
local cframe = rootPart.CFrame
local rotation = cframe - cframe.Position
local deltaCF = rotation:ToObjectSpace(lastCF)
lastCF = rotation
if state.Name ~= "Freefall" then
airAccel = 0
return
end
local activeForce = (rootPart.Velocity * XZ_VECTOR3).Magnitude
if activeForce > airAccel then
airAccel = activeForce
elseif activeForce < airAccel then
local ratio = airAccel / activeForce
local apply = Vector3.new(ratio, 1, ratio)
rootPart.Velocity = rootPart.Velocity * apply
end
rootPart.Velocity = deltaCF:VectorToObjectSpace(rootPart.Velocity) + humanoid.MoveDirection
end
RunService.Heartbeat:Connect(stepPhysics)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment