Hey there,
I have a script that forces the player to look left or right based on the Orientation of the humanoid root part.
It works well when going right (0,0,0) but when I turn around it just teleports me back. I didn’t even do any position changing.
local function Round(to_round,n)
local divided = to_round / n
local rounded = n * math.floor(divided)
return rounded
end
script.Parent.OnServerEvent:Connect(function(Player,Character,o)
--o = Character:WaitForChild("HumanoidRootPart").Orientation
Character:WaitForChild("HumanoidRootPart").Orientation = Vector3.new(0,Round(o.Y,180),0)
end)
I already have the left and right movement. But if someone quickly presses one of the keys the player can sometimes get stuck looking backwards or forwards. So I want to rotate them to always be turned left or right.
me and a friend used this local script to make a 2d type game that I think you are aiming for
local cam = workspace.CurrentCamera
local char = script.Parent
local hrp = char:WaitForChild("HumanoidRootPart")
local cas = game:GetService("ContextActionService")
cas:UnbindAction("moveForwardAction")
cas:UnbindAction("moveBackwardAction")
game:GetService("RunService").RenderStepped:Connect(function()
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = cam.CFrame:Lerp(CFrame.new(hrp.Position + Vector3.new(0, 5, 15), hrp.Position), 0.1)
end)
note: if someone quickly moves left and right while against a wall they will move forwards or backwards. Also put this script in starter player scripts
I think the information you give is too little to make an assesment about anything, but my first concern is that you seem to be using a remotevent to handle the orientation on the server side? Why not on the localscript?