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.
@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)
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.
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.
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.
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”)
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.