tl;dr: How do i calculate drag to (hopefully) have my air dash go the same distance as my ground dash
Hello, I’ve been working on a dash ability and one of the biggest issues I ran into was my air dash went further than the ground dash and I want them to go the same distance. My temp solution is to decrease the dash speed by 60% when in the air. It seems like if I truly wanna solve this though I need to implement some drag and so I’ve been doing a lot of research, but unfortunately math isn’t my strongest skill.
Here is my movement code
local horizontalInput,verticalInput = leftValue-rightValue, backwardValue-forwardValue
local x,z = horizontalInput,verticalInput
if input.isCameraRelative then
local cameraDir = (game.Workspace.CurrentCamera.CFrame.lookVector * Vector3.new(1, 0, 1)).Unit
local yaw = math.atan2(cameraDir.x, cameraDir.z)
verticalInput = x * -math.sin(yaw) - z * math.cos(yaw) --x,z
horizontalInput = x * math.cos(yaw) - z * math.sin(yaw) --x,z
else
horizontalInput,verticalInput = rightValue-leftValue, backwardValue-forwardValue
end
local velocity = Vector3.new(horizontalInput,0,verticalInput)
-- Movement and Rotation
if velocity.Magnitude > 0.5 then
root.CFrame += velocity.Unit * moveSpeed.value * Matter.useDeltaTime()
local goal = CFrame.new(root.CFrame.Position, root.CFrame.Position + velocity.Unit)
root.CFrame = root.CFrame:Lerp(goal, rotationSmoothness)
end
Dash Code
if humanoid.FloorMaterial == Enum.Material.Air then
root.Velocity = root.CFrame.LookVector * (speed/100) * dashModifer
else
root.Velocity = root.CFrame.LookVector * speed
end
And here is me attempting to implement a drag formula
local bsa = 1/6 * (1.54 * 2.8) * 0.5 -- area of a body(?)
local drag = 1.3 * 1.29 * math.sqrt(velocity.Magnitude) * bsa / 2 --D = Cd r V^2 A / 2
Lastly, here are some quick videos showing the difference between air and ground dash.