This issue started when I started to test the jeeps, it first started flinging.However, I Put the right modification into the jeep to make it not fling by reducing the suspension value. As of now I have a big problem the speeds are fps dependent which means it just decreases on low fps and increases on high fps. I’ve tried multiple methods like Lerp smoothing, but it did not go at the same speed and pace as normal at 60 fps. How do I fix this?
here’s the code
while character.Humanoid.SeatPart == car.DriveSeat do
game:GetService("RunService").RenderStepped:wait()
--Broken gyro input
--[[if userInputService.GyroscopeEnabled then
local inputObject, cframe = userInputService:GetDeviceRotation()
local up = cframe:vectorToWorldSpace(Vector3.new(0, 1, 0))
local angle = (1 - up.Y) * (math.abs(up.X) / up.X)
movement = Vector2.new(angle, movement.Y)
end]]
if IsGrounded() then
if movement.Y ~= 0 then
local velocity = car.Chassis.CFrame.lookVector * movement.Y * stats.Speed.Value
car.Chassis.Velocity = car.Chassis.Velocity:Lerp(velocity, 0.1)
bodyVelocity.maxForce = Vector3.zero
else
bodyVelocity.maxForce = Vector3.new(mass / 1.1, mass / (2*x), mass / 1.1 )
end
local rotVelocity = car.Chassis.CFrame:vectorToWorldSpace(Vector3.new(movement.Y * stats.Speed.Value / 50, 0, -car.Chassis.RotVelocity.Y * 5 * movement.Y))
local speed = -car.Chassis.CFrame:vectorToObjectSpace(car.Chassis.Velocity).unit.Z
rotation = rotation + math.rad((-stats.Speed.Value / 5) * movement.Y)
if math.abs(speed) > 0.1 then
rotVelocity = rotVelocity + car.Chassis.CFrame:vectorToWorldSpace((Vector3.new(0, -movement.X * speed * stats.TurnSpeed.Value, 0)))
bodyAngularVelocity.maxTorque = Vector3.zero
else
bodyAngularVelocity.maxTorque = Vector3.new(mass / x, mass/ 1.1 * x , mass/ 1.1)
end
car.Chassis.RotVelocity = car.Chassis.RotVelocity:Lerp(rotVelocity, 0.1)
--bodyVelocity.maxForce = Vector3.new(mass / 3, mass / 6, mass / 3)
--bodyAngularVelocity.maxTorque = Vector3.new(mass / 6, mass / 3, mass / 6)
else
bodyVelocity.maxForce = Vector3.zero
bodyAngularVelocity.maxTorque = Vector3.zero
end
for i, part in pairs(car:GetChildren()) do
if part.Name == "Thruster" then
UpdateThruster(part)
end
end
end
for i, v in pairs(car:GetChildren()) do
if v:FindFirstChild("BodyThrust") then
v.BodyThrust:Destroy()
end
end
bodyVelocity:Destroy()
bodyAngularVelocity:Destroy()
camera.CameraType = oldCameraType
userInputService.ModalEnabled = false
script:Destroy()
end)
Change game:GetService("RunService").RenderStepped:wait() to local dt = game:GetService("RunService").RenderStepped:Wait()
Then in any section where you add to the velocity, multiply the velocity addition by (dt * 60), assuming you were testing on 60 FPS
while character.Humanoid.SeatPart == car.DriveSeat do
game:GetService("RunService").RenderStepped:wait()
--Broken gyro input
--[[if userInputService.GyroscopeEnabled then
local inputObject, cframe = userInputService:GetDeviceRotation()
local up = cframe:vectorToWorldSpace(Vector3.new(0, 1, 0))
local angle = (1 - up.Y) * (math.abs(up.X) / up.X)
movement = Vector2.new(angle, movement.Y)
end]]
if IsGrounded() then
if movement.Y ~= 0 then
local velocity = car.Chassis.CFrame.lookVector * movement.Y * stats.Speed.Value * dt * 60
car.Chassis.Velocity = car.Chassis.Velocity:Lerp(velocity, 0.1)
bodyVelocity.maxForce = Vector3.zero
else
bodyVelocity.maxForce = Vector3.new(mass / 1.1, mass / (2*x), mass / 1.1 )
end
local rotVelocity = car.Chassis.CFrame:vectorToWorldSpace(Vector3.new(movement.Y * stats.Speed.Value / 50, 0, -car.Chassis.RotVelocity.Y * 5 * movement.Y) * dt * 60)
local speed = -car.Chassis.CFrame:vectorToObjectSpace(car.Chassis.Velocity).unit.Z * dt * 60
rotation = rotation + math.rad((-stats.Speed.Value / 5) * movement.Y) * dt * 60
if math.abs(speed) > 0.1 then
rotVelocity = rotVelocity + car.Chassis.CFrame:vectorToWorldSpace((Vector3.new(0, -movement.X * speed * stats.TurnSpeed.Value, 0)))
bodyAngularVelocity.maxTorque = Vector3.zero
else
bodyAngularVelocity.maxTorque = Vector3.new(mass / x, mass/ 1.1 * x , mass/ 1.1)
end
car.Chassis.RotVelocity = car.Chassis.RotVelocity:Lerp(rotVelocity, 0.1)
--bodyVelocity.maxForce = Vector3.new(mass / 3, mass / 6, mass / 3)
--bodyAngularVelocity.maxTorque = Vector3.new(mass / 6, mass / 3, mass / 6)
else
bodyVelocity.maxForce = Vector3.zero
bodyAngularVelocity.maxTorque = Vector3.zero
end
for i, part in pairs(car:GetChildren()) do
if part.Name == "Thruster" then
UpdateThruster(part)
end
end
end
for i, v in pairs(car:GetChildren()) do
if v:FindFirstChild("BodyThrust") then
v.BodyThrust:Destroy()
end
end
bodyVelocity:Destroy()
bodyAngularVelocity:Destroy()
camera.CameraType = oldCameraType
userInputService.ModalEnabled = false
script:Destroy()
end)
it may work but it overshoots its speed and you’re mainly focusing on the lerp and my method worked with it just going forwards it didn’t work on turns
2 ways that i know of to make lerp consistent with FPS
Set the Alpha to math.clamp(Alpha * DeltaTime * 60, 0.008, 1)
Set the Alpha to 1 - math.exp(-Speed * DeltaTime) (trickier since the speed isn’t fraction of target now, if it doesn’t work set the -Speed to Speed, basically positive, and you may need to set it to a very high number)
local lastTime = tick()
game:GetService("RunService").PreSimulation:Connect(function(_)
local currentTime = tick()
local deltaTime = currentTime - lastTime
lastTime = currentTime
local lerpAlpha = 0.075 * deltaTime * 60
if car:FindFirstChild("DriveSeat") and character.Humanoid.SeatPart == car.DriveSeat then
if IsGrounded() then
if movement.Y ~= 0 then
local velocity = car.Chassis.CFrame.lookVector * movement.Y * stats.Speed.Value
-- Keep the equivalent scaling
car.Chassis.Velocity = car.Chassis.Velocity:Lerp(velocity ,lerpAlpha)
bodyVelocity.maxForce = Vector3.zero
else
bodyVelocity.maxForce = Vector3.new(mass / 1.1, mass / (2*x), mass / 1.1 )
end
local rotVelocity = car.Chassis.CFrame:vectorToWorldSpace(Vector3.new(movement.Y * stats.Speed.Value/ 50, 0, -car.Chassis.RotVelocity.Y * 5 * movement.Y))
local speed = -car.Chassis.CFrame:vectorToObjectSpace(car.Chassis.Velocity).unit.Z
rotation = rotation + math.rad((-stats.Speed.Value / 5) * movement.Y)
if math.abs(speed) > 0.1 then
rotVelocity = rotVelocity + car.Chassis.CFrame:vectorToWorldSpace((Vector3.new(0, -movement.X * speed * stats.TurnSpeed.Value , 0)))
bodyAngularVelocity.maxTorque = Vector3.zero
else
bodyAngularVelocity.maxTorque = Vector3.new(mass / x, mass/ 1.1 * x , mass/ 1.1)
end
car.Chassis.RotVelocity = car.Chassis.RotVelocity:Lerp(rotVelocity ,lerpAlpha)
else
bodyVelocity.maxForce = Vector3.zero
bodyAngularVelocity.maxTorque = Vector3.zero
end
for i, part in pairs(car:GetChildren()) do
if part.Name == "Thruster" then
UpdateThruster(part)
end
end
else
for i, v in pairs(car:GetChildren()) do
if v:FindFirstChild("BodyThrust") then
v.BodyThrust:Destroy()
end
end
script:Destroy()
bodyVelocity:Destroy()
bodyAngularVelocity:Destroy()
camera.CameraType = oldCameraType
userInputService.ModalEnabled = false
end
end)
it goes at the same pace when moved fowards and backwards but doesn’t when turns happen