Mobile vehicle controls appear to be broken [Unresolved]

I’m still having issues with mobile input in live games.

Infrequently I’ll be able to get input from the simulated mobile device in studio - however in game it is like Mobile controls do not drive VehicleSeats, least not in my case.

I really have no idea what is going on - I’ve been trying to fix this for about a month in-between work.

This is part of the script that takes in user input using the UserInputService.
The ‘throttle’, ‘steer’ and ‘brake’ variables are the end result of the ‘GetInput’ function.

In-game - the developer tells me that it detects the user input on mobile and is printing appropriately.
However the ‘local t,s’ variables at the bottom of the GetInput function do not update to reflect the VehicleSeat’s throttle and steer - or they are and Roblox’s mobile controls don’t update the VehicleSeat’s throttle and steer properties.

local player = game.Players.LocalPlayer
local char = script.Parent
local mouse = player:GetMouse()
local car = script:WaitForChild("Car").Value
local seat = car:WaitForChild("VehicleSeat")
local chassis = car:WaitForChild("Chassis")
local engine = chassis:WaitForChild("Engine")
local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")

local throttle,steer,brake = 0,0,0
local uThrottle,uBrake,uSteer = 0,0,0

function GetInput(inputObject)
	if inputObject then -- this part of the script is simply for detecting keyboard and controller input;
		if inputObject.KeyCode == Enum.KeyCode.W or inputObject.KeyCode == Enum.KeyCode.S then
			uThrottle = Keys["w"] and 1 or 0
			uBrake = Keys["s"] and 1 or 0
		end
		if inputObject.KeyCode == Enum.KeyCode.A or inputObject.KeyCode == Enum.KeyCode.D then
			uSteer = Keys["d"] and 1 or (Keys["a"] and -1 or 0)
		end
	
	
		if inputObject.KeyCode == Enum.KeyCode.ButtonR2 then
			uThrottle =  inputObject.Position.Z
		elseif inputObject.KeyCode == Enum.KeyCode.ButtonL2 then
			uBrake = inputObject.Position.Z
		end
	
		if inputObject.KeyCode == Enum.KeyCode.Thumbstick1 then
			uSteer =  inputObject.Position.X
		end
	
		if inputObject.KeyCode == Enum.KeyCode.ButtonA or inputObject.KeyCode == Enum.KeyCode.Space then
			Handbrake(Keys[" "] or inputObject.Delta.Z == 1)
		end
			
			
		--I want to include gyro-based steering, but this doesn't work either.
		if inputObject.UserInputType == Enum.UserInputType.Gyro or inputObject.UserInputType == Enum.UserInputType.Accelerometer then
			-- Translate Gyro to Steering
			local d = inputObject.Delta
			local p = inputObject.Position
			local s = inputObject.UserInputState
			print(inputObject.UserInputType..": Delta:",d,"/// Position:",p,"/// State:",s)
			uSteer = d.Z
		--	print("GYRO Delta:",d)
		--	print("GYRO   Pos:",p)
		--	print("GYRO State:",s)
		end

		if inputObject.KeyCode == Enum.KeyCode.ButtonY then --  inputObject.KeyCode == Enum.KeyCode.T or
			ExitCar()
		end
		if inputObject.KeyCode == Enum.KeyCode.DPadDown then --inputObject.KeyCode == Enum.KeyCode.G or 
			RecoverToStart()
		end
		if inputObject.KeyCode == Enum.KeyCode.DPadUp then -- inputObject.KeyCode == Enum.KeyCode.R or 
			ResetOrientation()
		end
	end

	local t,s = seat.Throttle + seat.ThrottleFloat + uThrottle - uBrake, seat.Steer + seat.SteerFloat + uSteer
	throttle = math.clamp(t,-1,1)
	brake = t < 0 and math.clamp(uBrake + -t,0,1) or 0
	steer = math.clamp(s,-1,1)
	print("Seat,",seat,"///",t,s,"T:",throttle,"B:",brake,"S:",steer,"Type:",inputObject and inputObject.UserInputType, "Delta:",inputObject and inputObject.Delta)
	ControlCar()
end


UserInputService.InputChanged:Connect(GetInput)
UserInputService.InputBegan:Connect(GetInput)
UserInputService.InputEnded:Connect(GetInput)



game:GetService("RunService").Heartbeat:Connect(function(dt)
	--SetGravityDirection()
	if not seat or not car or not seat.Parent or not car.Parent or not seat.Occupant then
		ExitCar()
		script.Disabled = true
		return
	end
	
	GetInput(nil)
end)

By the way - please let me know what you think of my feature request for adding better development support for mobile devices.

1 Like

Try implementing the character move controls into the vehicle controls. I believe that would be easier, and just make a separate ui for that.