Improving Car Control Responsiveness

Currently, I’ve been messing with cars working on PGS Physics, and I used some baseline code I found on the DevHub. One of the main complaints I have with the method I’m currently working with, is a small bit of input lag, to the point where everyone I’ve talked to who tests my cars have said it’s to the point of being noticeable.

My current code is as such:

local car = seat.Parent
local leftDrive = car.RearAxle.LeftDrive
local rightDrive = car.RearAxle.RightDrive
local steerHingeR = car.AxleR.SteerHingeR
local steerHingeL = car.AxleL.SteerHingeL

local function onChanged (property)	
	if property == "Steer" then
		local steeringAngle = seat.Configuration.SteerAngle.Value
		local turnSpeed = seat.Configuration.TurnSpeed.Value
		steerHingeR.TargetAngle = steeringAngle * seat.Steer
		steerHingeL.TargetAngle = steeringAngle * seat.Steer
		steerHingeR.AngularSpeed = turnSpeed
		steerHingeL.AngularSpeed = turnSpeed
	if property == "Throttle" then
		local maxSpeed = seat.Configuration.MaxSpeed.Value
		local torque = seat.Configuration.Torque.Value * 1000
		leftDrive.AngularVelocity = maxSpeed * seat.Throttle
		rightDrive.AngularVelocity = -maxSpeed * seat.Throttle
		rightDrive.MotorMaxTorque = torque
		leftDrive.MotorMaxTorque = torque


Any help to reduce some of this latency would be greatly appreciated. Have considered that a while loop would have less latency, because of it’s constant running, right? My concern would be a limit on how many cars I could have running realistically before it destroys the server.

Cars are stationed here.

1 Like

If this is a Server script then that may be the cause of input lag.

Try setting network ownership to the driver then handling user input from a local script.
That will also give you the flexibility of making custom control schemes.

How would I go about setting network ownership?

If you are using a vehicle seat, I think it automatically sets ownership of the model when a player sits in it, but I could be wrong.

To set Network Ownership manually, just call SetNetworkOwner of the part.

1 Like

In practice here, I’m confused how I use this though tbh.

Also, it seems like Network Ownership is auto-set on vehicles. The only case this is tricky is when a passenger messes things up, but I have no passenger seats in my vehicles, so that’s not a problem.

That’s interesting, I didn’t know network ownership was automatically set. But that kind of makes sense anyway.

In my case when a user requests a car - I spawn the car by the user, set network ownership to that user
Then, I place the Local Driver script I have made (that handles controls and movement of the vehicle) into the player and enable it.

Since LocalScripts run the user’s machine there should be no delay in (e.g.) requesting to steer left and performing that action directly on the vehicle.

Whereas with a Server Script - the script has to listen to the VehicleSeat (which takes user input), perform the action, then replicate that action to all the users.

1 Like

By setting network ownership, you allow physics of vehicles to be changed locally so that there isn’t any latency for the player.

What’s the best way to go about doing that? Like as in, what’s the best way to give the player a local script to control the car?

And I’m assuming that local script needs UserInputService to read the player’s requests?

My latency isn’t from the physics of the vehicle I believe. I think it’s more just the waiting to get input from the vehicle seat, which is got from the player. So it’s just, latency of having the vehicleseat as a middle man.

Yeah, so with network ownership, you can use input service and locally move the vehicle instead of using a vehicle seat.

I actually had the exact same problem with a car system of my own. When driving, you have NetworkOwnership over the vehicle, therefore you can use a local script for turning, I personally did this based on MoveVectors so I can have controller and mobile support.

You can still use a vehicle seat, just do all turning locally, act as if FE doesn’t exist.

1 Like

I’m just confused, where does the local script go? Currently I have a server script inside the vehicle seat, listening for the vehicle seat to change.

Put the local script in the player backpack when they get in the car and remove it when they get out of it. Dying will automatically remove the script.

1 Like

I’ll give it a go and tell you what happens!

Were you able to solve the issue?

1 Like

I believe so. It appears I’ve removed a lot of the latency issues I had. Thanks everyone!