BodyGyro oversensitive on low fps

Currently I have a car that turns and orientates itself to the ground using a BodyGyro. The ground orietation happens through a cross product of 4 separate raycasts on each corner of the car. The result is then multiplied by CFrame.Angles() which is used to steer the car.
The problem is that the steering seems to be more and more sensitive as the client’s fps goes down.
60fps:


~30fps:

~10fps:

Here is the code:

--align car to surface/steer
	local smoothsteer = math.clamp(math.round(mag*0.75),0,10)
	steerdir = CFrame.Angles(0,math.rad((tune.steerAmount/10)*smoothsteer*grounded)*-steer.Value,0)
	
	local align = Vector3.new(0,1,0):Cross((rays["FL"]-rays["RR"]):Cross(rays["RL"]-rays["FR"]).Unit)
	local aligncf = CFrame.fromAxisAngle(align.Magnitude == 0 and Vector3.new(1,0,0) or align.Unit, (math.asin(align.Magnitude)))
	local newcf = CFrame.fromMatrix(car.Position,carcf.RightVector,aligncf.UpVector,carcf.LookVector)
	gyrocf = newcf*steerdir
	
	--update gyro
	gyro.CFrame = gyrocf

I confirmed that the cross product is causing this, however I have no clue how to fix the problem. Any help is appreciated.

This happens because the time interval between frames becomes longer as the FPS decreases, causing larger changes in object orientation between frames. You can adjust your code to take into account the time interval between frames when applying rotations Xx

By multiplying the smoothness factor (smoothSteer) by the deltaTime, you ensure that the steering sensitivity is consistent regardless of the frame rate! :white_heart:

I figured out that the steering itself doesn’t contribute to it, here you can see I am going in a straight line on ~10fps and the car starts steering on its’ own

Then the issue may lie in other parts of your code or the physics simulation, if you’d like to provide more of your code so I can help Xx

I figured it out, turns out removing the car’s LookVector from the last argument in CFrame.fromMatrix fixes the problem

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.