I am making a top down game similar to snake and I want the player to keep walking even if they aren't holding w or dragging their cursor on mobile. The player would be able to turn 90 degrees by pressing a or d. I have made the player move without holding w or dragging their cursor on mobile but they can not turn by 90 degrees by pressing a or d. The camera is also a part that is in the sky rotated towards the baseplate. When they press a or d it just makes them turn for a millisecond then stop, here's how it looks like: https://gyazo.com/d3faaf808703454f65fa1ff8d6a7ba24
I put this in StarterPlayerScripts
local LocalPlayer = game:GetService("Players").LocalPlayer local Controls = require(LocalPlayer.PlayerScripts.PlayerModule):GetControls() Controls:Disable()
I put this in StarterPlayerScripts
game.Players.LocalPlayer:Move(Vector3.new(0, 0, 1), true) local UIS = game:GetService("UserInputService") local function GetHrp() return game:GetService("Players").LocalPlayer.Character.HumanoidRootPart or game:GetService("Players").LocalPlayer.Character:FindFirstChildOfClass("Humanoid").RootPart end UIS.InputBegan:Connect(function(UserInputType) if UserInputType.KeyCode == Enum.KeyCode.A then GetHrp().CFrame = GetHrp().CFrame * CFrame.Angles(0,math.rad(90),0) elseif UserInputType.KeyCode == Enum.KeyCode.D then GetHrp().CFrame = GetHrp().CFrame * CFrame.Angles(0,math.rad(-90),0) end end)
this should help you
local UIS = game:GetService("UserInputService") local function GetHrp() return game:GetService("Players").LocalPlayer.Character.HumanoidRootPart or game:GetService("Players").LocalPlayer.Character:FindFirstChildOfClass("Humanoid").RootPart end UIS.InputBegan:Connect(function(InputType) if InputType.KeyCode == Enum.KeyCode.A then GetHrp().CFrame = GetHrp().CFrame * CFrame.Angles(0,math.rad(90),0) elseif InputType.Keycode == Enum.KeyCode.D then GetHrp().CFrame = GetHrp().CFrame * CFrame.Angles(0,math.rad(-90),0) end end)
Ok so essentially you want to make it that the player moves in the direction he is facing correct? So what you need to do is to make the script that makes the player move forward have a value called direction. Which is an vector3 value. Now you want to make the player move towards the value. Now instead of turning the player in a seperate script you can just make that script change the value. Kind of like an npc the player would move forward until you press a for example then it will cause the character to turn left and make the character walk that direction.
You havent provided the script which causes the player to go forward so I cant make a script for you.