Im trying to make it so a part will have the same Y orientation as the Y of the camera but weird inversion happens and im really confused…
Server Code:
game:GetService("ReplicatedStorage"):WaitForChild("RotatePlayer").OnServerEvent:connect(function(player,rot)
local players = workspace:WaitForChild("Players")
local playermodel = players:FindFirstChild(player.Name)
playermodel.Orientation = Vector3.new(0,rot,0)
end)
Client Code:
repeat wait() until game:IsLoaded()
repeat wait() until workspace:FindFirstChild("Players")
repeat wait() until workspace.Players:FindFirstChild(game:GetService("Players").LocalPlayer.Name)
print("game loaded")
local run_service = game:GetService("RunService")
local camera = workspace.Camera
local player = workspace.Players:FindFirstChild(game:GetService("Players").LocalPlayer.Name)
run_service.RenderStepped:connect(function()
local x,y,z= camera.CFrame:ToEulerAnglesXYZ()
game:GetService("ReplicatedStorage"):WaitForChild("RotatePlayer"):FireServer(y*55)
camera.CameraSubject = player
camera.CameraType = Enum.CameraType.Custom
end)
the *55 is just so its far enough ahead but without it the player moves about 0.1 studs.
I think I know what the problem is, :ToEulerAnglesXYZ() returns x, y, and z in radians, not degree’s. So you can use math.deg() to turn radians into degree’s. When you placed the orientation of the part the orientation is in degree’s. So use math.deg(), like this:
Hmm. I think you should try getting the lookvector of the camera instead and set it to the player’s orientation or cframe. And set the x and z to whatever the players orientation is originally
How about you try putting a body mover into your character and then setting the body movers cframe to the cframe of the camera and update every single frame
Your problem comes from the use of CFrame:ToEulerAnglesXYZ().
Essentially, it doesn’t actually return the orientation of the CFrame. I don’t exactly know what it returns, but it isn’t the same as just regular orientation. Just know that you probably don’t want to be using it (unless you know exactly what it returns). Instead, you should use CFrame:ToOrientation() (which is actually just the same thing as CFrame:ToEulerAnglesZYX() but the name is a lot more intuitive so I use it). In addition, the reason for it rotating so slowly, as stated above, is because it returns radians, while you want degrees. As such, you will have to use math.deg to convert it to radians.
Your final code should look like this (this is a modification of the code you posted).
repeat wait() until game:IsLoaded()
repeat wait() until workspace:FindFirstChild("Players")
repeat wait() until workspace.Players:FindFirstChild(game:GetService("Players").LocalPlayer.Name)
print("game loaded")
local run_service = game:GetService("RunService")
local camera = workspace.Camera
local player = workspace.Players:FindFirstChild(game:GetService("Players").LocalPlayer.Name)
run_service.RenderStepped:connect(function()
local x,y,z= camera.CFrame:ToOrientation()
game:GetService("ReplicatedStorage"):WaitForChild("RotatePlayer"):FireServer(math.deg(y))
camera.CameraSubject = player
camera.CameraType = Enum.CameraType.Custom
end)