How to make head look at camera only when orientation changes?

Camera:GetPropertyChangedSignal("CFrame"):Connect(function()
	Head.CFrame = CFrame.lookAt(Head.CFrame.Position, Camera.CFrame.Position) * CFrame.Angles(0, math.rad(180), 0)
end)

This works but I want to change the Head’s CFrame only when the orientation of the camera changes, since this will look at the camera when the position changes too.

5 Likes

And you can’t access the orientation of the camera either so yeah

3 Likes

Ok so apparently the orientation cannot be changed without the position changing so I guess there’s no solution to this.

2 Likes

use CFrame.Angles(). that should work.

2 Likes

I was asking if there was an event for this but turns out camera’s pos also changes when the orientation does so there’s no point.

2 Likes

There is always a way …

local lastCameraOrientation = Camera.CFrame - Camera.CFrame.Position

Camera:GetPropertyChangedSignal("CFrame"):Connect(function()
    local currentCameraOrientation = Camera.CFrame - Camera.CFrame.Position
    if currentCameraOrientation ~= lastCameraOrientation then
        Head.CFrame = CFrame.lookAt(Head.CFrame.Position, Camera.CFrame.Position) * CFrame.Angles(0, math.rad(180), 0)
        lastCameraOrientation = currentCameraOrientation
    end
end)

I need time to test my replies. Give a question a bit, so others can double check their answers.
Good luck.

3 Likes

Oh alright thanks 2112Jay, being a hero as always. If this works ill mark you as the solution.

3 Likes

Sadly didn’t work, as it’s still setting the CFrame when the position also changes. But it’s fine mate.

2 Likes

@2112Jay I recognized the problem with your post. your are not actually grabbing the orientation but the difference. I recommend @Amritss try with this change.

local lastCameraOrientation = Camera.CFrame:ToEulerAnglesXYZ

Camera:GetPropertyChangedSignal("CFrame"):Connect(function()
    local currentCameraOrientation = Camera.CFrame:ToEulerAnglesXYZ
    if currentCameraOrientation ~= lastCameraOrientation then
        Head.CFrame = CFrame.lookAt(Head.CFrame.Position, Camera.CFrame.Position) * CFrame.Angles(0, math.rad(180), 0)
        lastCameraOrientation = currentCameraOrientation
    end
end)
3 Likes

Thank you, if this works I’ll mark it as a solution too.

2 Likes

Ya I didn’t have time to really go into this solved instantly … but, that will work with a bit of love … It’s just a matter of being able to get the information you need and apply it.

1 Like

Sorry guys, I appreciate the support but this also is not working properly since when the position of the camera changes this still runs.

And by what I mean runs, I mean this line of code still runs:

I don’t think there’s a proper way to make it ONLY change when the camera’s orientation does. But thanks for trying.

1 Like

How is your camera set up? is it just like a normal camera or is it set up differently?

If its not set up like the normal camera then I could help otherwise I cant.

1 Like

It’s a regular camera set to custom.

3 Likes

This is annoying my flying script too since when the position of the camera changes, when I zoom in the character starts bugging out.

I was doing this to make a unique spectator thing but I think just using a regular freecam will be enough and I’ll preserve the flying script for myself as an admin.

2 Likes

This has worked for me so now I dont know at all so

2 Likes

It’s fine. I’ll do some other stuff thanks for trying.

3 Likes

Alright so I realised there is one way to sort of do this, using alignorientation. However the position would probably change with the orientation, so take it with a grain of salt.

Here you go …

local RunService = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local PlayerMouse = Player:GetMouse()
local Camera = workspace.CurrentCamera

local Character = Player.Character or Player.CharacterAdded:Wait()
local Head = Character:WaitForChild("Head")
local Neck = Head:WaitForChild("Neck")
local Torso = Character:WaitForChild("UpperTorso")
local Waist = Torso:WaitForChild("Waist")

local NeckOriginC0 = Neck.C0
local WaistOriginC0 = Waist.C0

Neck.MaxVelocity = 1/3

RunService.RenderStepped:Connect(function()
	local CameraCFrame = Camera.CFrame
	local Point = PlayerMouse.Hit.p

	if Camera.CameraSubject:IsDescendantOf(Character) then
		local Distance = (Head.Position - Point).magnitude
		local Difference = Head.Position.Y - Point.Y
		local Direction = (Head.Position - Point).Unit

		local HeadRotation = CFrame.Angles(-math.atan(Difference / Distance) * 0.5, Direction:Cross(Torso.CFrame.LookVector).Y * 1, 0)
		local WaistRotation = CFrame.Angles(-math.atan(Difference / Distance) * 0.5, Direction:Cross(Torso.CFrame.LookVector).Y * 0.5, 0)

		Neck.C0 = Neck.C0:lerp(NeckOriginC0 * HeadRotation, 0.25)
		Waist.C0 = Waist.C0:lerp(WaistOriginC0 * WaistRotation, 0.25)
	end
end)

Local Script in StarterPlayerScripts. Head follows camera … Tested.
The “only when orientation changes” didn’t work out, but doing it all the time did.
This was done with an R15 body also. For the other you’ll have to change a line:
local Torso = Character:FindFirstChild(“UpperTorso”) or Character:FindFirstChild(“Torso”)

1 Like

Thank you but I think i’ll stick with alignorientation, it’s more optimized probably since I wouldn’t have to use any sort of loops and it would only move the head when the orientation changes.

1 Like