Created
September 2, 2019 22:18
-
-
Save MaximumADHD/060febddd510d32426739a94e1eed234 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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