Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

The head does not face the same direction as the camera if the character's orientation isn't 0?

Asked by 6 years ago
Edited 6 years ago

Multiplying, dividing, subtracting, and adding the camera's lookvector x-axis by the HumanoidRootPart's lookvector x-axis didn't help at all.

plr = game.Players.LocalPlayer
char = game.Workspace:WaitForChild(plr.Name)

workspace.CurrentCamera.Changed:connect(function(propString)
    if propString == 'CFrame' then
        char.Torso.Neck.C1 = CFrame.Angles(workspace.CurrentCamera.CFrame.lookVector.Y*-1,workspace.CurrentCamera.CFrame.lookVector.X,0)
        char.Torso.Neck.C0 = CFrame.new(0,1.5,0)
    end
end)

1 answer

Log in to vote
1
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
6 years ago

C0/C1 are relative offsets based on the existing orientation of the parts. You're using the camera's world-space CFrame, so the translation made will only look right when the parts in the character have no rotation. Translating the camera into a reference frame relative to the character's rotation first fixes this:

local look = (char.Torso.CFrame:inverse()*workspace.CurrentCamera.CFrame).lookVector
char.Torso.Neck.C1 = CFrame.Angles(-look.Y, look.X, 0)
char.Torso.Neck.C0 = CFrame.new(0, 1.5, 0)

or if you don't want C1,

local look = (char.Torso.CFrame:inverse()*workspace.CurrentCamera.CFrame).lookVector
char.Torso.Neck.C0 = CFrame.Angles(look.Y, -look.X, 0) + Vector3.new(0, 1.5, 0)
char.Torso.Neck.C1 = CFrame.new()
Ad

Answer this question