WASD Movements to Mobile Controls

Hiya.

I’m working on a game at the moment, and there’s horses for the Guards to ride, however, I don’t know how to make them mobile compatible.

Here’s what I have:

userInputService.InputBegan:connect(function(inputObject, gameProcessedEvent)
	if not gameProcessedEvent then
		if inputObject.KeyCode == Enum.KeyCode.W or inputObject.KeyCode == Enum.KeyCode.Up then
			movement = Vector3.new(movement.X, movement.Y, -1)
		elseif inputObject.KeyCode == Enum.KeyCode.S or inputObject.KeyCode == Enum.KeyCode.Down then
			movement = Vector3.new(movement.X, movement.Y, 1)
		elseif inputObject.KeyCode == Enum.KeyCode.A or inputObject.KeyCode == Enum.KeyCode.Left then
			movement = Vector3.new(-1, movement.Y, movement.Z)
		elseif inputObject.KeyCode == Enum.KeyCode.D or inputObject.KeyCode == Enum.KeyCode.Right then
			movement = Vector3.new(1, movement.Y, movement.Z)
		elseif inputObject.KeyCode == Enum.KeyCode.Space then
			local ray = Ray.new(horse.HumanoidRootPart.Position + Vector3.new(0, -4.3, 0), Vector3.new(0, -1, 0))
			local hit, position = game.Workspace:FindPartOnRay(ray, horse)
			if hit and hit.CanCollide then
				horse.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
			end
		elseif inputObject.KeyCode == Enum.KeyCode.LeftShift then
			humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
		end
	end
end)

I am trying to make it so that the mobile movement features can work with this horse. Anyone got some tips?

1 Like

You can make GUI that, when held down, will make the horse move forwards, backwards, etc.

That’s very clumped and not what I’m going for, plus, it doesn’t allow for easy and smooth movements. I’m looking to make the implemented mobile controls work with the movement of this horse, perhaps by getting the direction of the movement and adding the force there?

Maybe you can change the player’s speed and jump height to match the horses, and then weld the player’s avatar to the horse to give the illusion your riding it?

Nah, that’d force me to re-write the entire code. I’m just wondering if there’s anyway to find the direction they’re going and apply force to that direction?

I’m not sure how to do that, sorry :sweat_smile:.

Hey i believe you would want to work with ContextActionService refer to this API reference article

How did you make it work with the mobile controls?