I have a game that you can get high speeds, it works fine but when you collide with something the player gets launched into the sky. (i can’t lower the MaxForce because in this game players need to get very fast)
Here’s the moviment code:
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local char = script.Parent
local hrp = char.HumanoidRootPart
local humanoid = char.Humanoid
local rootAttachment = hrp:WaitForChild("RootAttachment")
local MOVE_SPEED = player:WaitForChild("leaderstats"):WaitForChild("Speed")
local TURBO_TIME = player:WaitForChild("Values"):WaitForChild("TurboTime")
local TURBO_ENABLED = player:WaitForChild("Values"):WaitForChild("TurboEnabled")
local ACCELERATION = 7
local DECELERATION = 25
local LinearVelocity = Instance.new("LinearVelocity", hrp)
LinearVelocity.Attachment0 = rootAttachment
LinearVelocity.RelativeTo = Enum.ActuatorRelativeTo.World
LinearVelocity.VelocityConstraintMode = Enum.VelocityConstraintMode.Plane
LinearVelocity.PrimaryTangentAxis = Vector3.new(1, 0, 0)
LinearVelocity.SecondaryTangentAxis = Vector3.new(0, 0, 1)
LinearVelocity.MaxForce = math.huge
RunService.Heartbeat:Connect(function(dt)
local currentAcceleration = ACCELERATION
local currentDeceleration = DECELERATION
if humanoid.FloorMaterial == Enum.Material.Air then
currentDeceleration = 0.6
end
local moveDirection = humanoid.MoveDirection
local speedMultiplier = 1
local minVelocity = 10
local maxVelocity = math.huge
if TURBO_ENABLED.Value then
speedMultiplier *= 2
minVelocity = 150
end
local targetVelocity = Vector2.new(moveDirection.X, moveDirection.Z) * math.clamp(MOVE_SPEED.Value * 0.1 * speedMultiplier + 100, minVelocity, maxVelocity)
local deltaVelocity = targetVelocity - LinearVelocity.PlaneVelocity
local accelerationRate = if moveDirection.Magnitude > 0 then currentAcceleration else currentDeceleration
LinearVelocity.PlaneVelocity += deltaVelocity * accelerationRate * dt
hrp.AssemblyLinearVelocity = Vector3.new(hrp.AssemblyLinearVelocity.X, math.clamp(hrp.AssemblyLinearVelocity.Y, -3000, 450), hrp.AssemblyLinearVelocity.Z)
end)