1. I’m trying to fix the default roblox racing template cars from flipping out when certain players have below 60 or above 60fps and provide them a stable fun driving experience.
- Random players are having their cars flip over instantly when driving forward or making turns and it seems to be users that have less than 60FPS or more than 60FPS with an unlocker program, meanwhile some players don’t flip out at all and enjoy driving normally. I’ve looked into possible problems like the runservice render stepped, stepped, heartbeat, I’ve tried changing the physicssteppingmethod from default, fixed, adaptive (which did nothing) I’m not sure what to do or what I’m overlooking.
Here’s the default roblox racing template place that I am using the exact cars from
and the exact car model and scripts I am using for my game
BuggyDefaultCarReference.rbxm (46.8 KB)
RayCastModule script:
local module = {}
function module.new(startPosition, startDirection)
local maxDistance = startDirection.magnitude
local direction = startDirection.unit
local lastPosition = startPosition
local distance = 0
local ignore = {}
local hit, position, normal
repeat
local ray = Ray.new(lastPosition, direction * (maxDistance - distance))
hit, position, normal = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignore, false, true)
if hit then
if not hit.CanCollide then
table.insert(ignore, hit)
end
end
distance = (startPosition - position).magnitude
lastPosition = position
until distance >= maxDistance - 0.1 or (hit and hit.CanCollide)
return hit, position, normal
end
return module
Snippet from the LocalCarScript related to Runservice
--spawn(function()
while game:GetService("RunService").Heartbeat:wait() and car:FindFirstChild("DriveSeat") and character.Humanoid.SeatPart == car.DriveSeat do
--game:GetService("RunService").RenderStepped:wait()
if IsGrounded() then
if movement.Y ~= 0 then
local velocity = humanoidRootPart.CFrame.lookVector * movement.Y * stats.Speed.Value
humanoidRootPart.Velocity = humanoidRootPart.Velocity:Lerp(velocity, 0.1)
bodyVelocity.maxForce = Vector3.new(0, 0, 0)
else
bodyVelocity.maxForce = Vector3.new(mass / 2, mass / 4, mass / 2)
end
local rotVelocity = humanoidRootPart.CFrame:vectorToWorldSpace(Vector3.new(movement.Y * stats.Speed.Value / 50, 0, -humanoidRootPart.RotVelocity.Y * 5 * movement.Y))
local speed = -humanoidRootPart.CFrame:vectorToObjectSpace(humanoidRootPart.Velocity).unit.Z
rotation = rotation + math.rad((-stats.Speed.Value / 5) * movement.Y)
if math.abs(speed) > 0.1 then
rotVelocity = rotVelocity + humanoidRootPart.CFrame:vectorToWorldSpace((Vector3.new(0, -movement.X * speed * stats.TurnSpeed.Value, 0)))
bodyAngularVelocity.maxTorque = Vector3.new(0, 0, 0)
else
bodyAngularVelocity.maxTorque = Vector3.new(mass / 4, mass / 2, mass / 4)
end
humanoidRootPart.RotVelocity = humanoidRootPart.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.new(0, 0, 0)
bodyAngularVelocity.maxTorque = Vector3.new(0, 0, 0)
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
script:Destroy()
--end)
CarScript snippet related to runservice
--spawn(function()
while true do
game:GetService("RunService").Stepped:wait()
for i, part in pairs(car:GetChildren()) do
if part.Name == "Thruster" then
UpdateThruster(part)
end
end
if car.DriveSeat.Occupant then
local ratio = car.DriveSeat.Velocity.magnitude / stats.Speed.Value
car.EngineBlock.Running.Pitch = 1 + ratio / 4
bodyPosition.MaxForce = Vector3.new()
bodyGyro.MaxTorque = Vector3.new()
else
local hit, position, normal = Raycast.new(car.Chassis.Position, car.Chassis.CFrame:vectorToWorldSpace(Vector3.new(0, -1, 0)) * stats.Height.Value)
if hit and hit.CanCollide then
bodyPosition.MaxForce = Vector3.new(mass / 5, math.huge, mass / 5)
bodyPosition.Position = (CFrame.new(position, position + normal) * CFrame.new(0, 0, -stats.Height.Value + 0.5)).p
bodyGyro.MaxTorque = Vector3.new(math.huge, 0, math.huge)
bodyGyro.CFrame = CFrame.new(position, position + normal) * CFrame.Angles(-math.pi/2, 0, 0)
else
bodyPosition.MaxForce = Vector3.new()
bodyGyro.MaxTorque = Vector3.new()
end
end
end
--end)
- People seem to have similar problems with their own custom raycast rigs on the developerforum but I’m not sure if this model is having the same problems as them and can be traced back to the raycast being to blame or the runservice physics rendering.
I am not familiar with raycasting part of the car and I assume most of the flipping problem lay with the RunService because the flipping seems to directly correlate with players having less or more than normal FPS (60FPS) feel free to download the car file or open up the template place yourself and experiment with driving yourself or using an fpsunlock type program to test different framerates.
Appreciate if anyone can provide solutions so I can make amendments to this car system, it’s a really good, clean, moddable system and I would rather fix this system than make my own, thank you!