VehicleController endlessly goes in reverse (with player script fix)

This is a bit of an edge case I found, but the new VehicleController module doesn’t take into account a UserInputState of “Cancel”. As a result of this, if it ever fires (the circumstances of which I’m not fully aware, but it happened enough for me to notice), the controller interprets this as the left trigger to go backwards. As the left trigger did not actually fire, there’s nothing to return the throttle to 0. For those without gamepads, this means it can only be solved by rejoining the game.

Luckily this is a pretty simple fix:

Lines 119-140 currently look like this:

function VehicleController:OnThrottleAccel(actionName, inputState, inputObject)
	self.acceleration = (inputState ~= Enum.UserInputState.End) and -1 or 0
	self.throttle = self.acceleration + self.decceleration
end

function VehicleController:OnThrottleDeccel(actionName, inputState, inputObject)

	self.decceleration = (inputState ~= Enum.UserInputState.End) and -1 or 0
	self.throttle = self.acceleration + self.decceleration
end

function VehicleController:OnSteerRight(actionName, inputState, inputObject)
	self.turningRight = (inputState ~= Enum.UserInputState.End) and 1 or 0
	self.steer = self.turningRight + self.turningLeft
end

function VehicleController:OnSteerLeft(actionName, inputState, inputObject)
	self.turningLeft = (inputState ~= Enum.UserInputState.End) and -1 or 0
	self.steer = self.turningRight + self.turningLeft
end

All that needs to be done is treat “Cancel” the way it Treats “End”

function VehicleController:OnThrottleAccel(actionName, inputState, inputObject)
	local ended = (inputState == Enum.UserInputState.End or inputState == Enum.UserInputState.Cancel)
	self.acceleration = (not ended) and -1 or 0
	self.throttle = self.acceleration + self.decceleration
end

And that’s about it. Not sure why “Cancel” is even being called when there isn’t even a gamepad connected, but regardless, it should be treated as an “End” in this code.

Edit: In my fix, for the acceleration ternary I had “ended and -1 or 0”, this should be “(not ended) and -1 or 0” or “ended and 0 or -1”

1 Like