Hello, I’m trying to make a 2d game which involves fighting and I want to know if anyone knows how to make a script that will instantly turn the player Left or Right if the player press’ the letters A or D on the keyboard. I know it involves something with CFrame but I’m not quite sure I can do it. I’ll appreciate it very much if you could help
local players = game:GetService("Players")
local player = players.LocalPlayer or players.PlayerAdded:wait()
local character = player.Character or player.CharacterAdded:wait()
local HMR = character:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(input, isProc)
if input.KeyCode == Enum.KeyCode.A then
HMR.Orientation += Vector3.new(0, -90, 0)
elseif input.KeyCode == Enum.KeyCode.E then
HMR.Orientation += Vector3.new(0, 90, 0)
end
end)
This is probably what you’re looking for.
2 Likes
You can set the humanoid root part’s cframe to CFrame.lookAt(HumanoidRootPart.Position, HumanoidRootPart.Position + Vector3.new(-1, 0, 0))
example for facing -x direction
I do that to turn the Player in the direction that he is shooting, but when you press W, he just keeps walking the same direction that he was b4.
It’s a bit buggy. do you think you can help. I understand what’s going on but I don’t know how to fix it
You might need to change the Vector3 values’ components slightly (to fit your needs). Might be worth adding a debounce to add a cooldown on turning too.