I’m currently attempting to make the camera rotate when the head rotates, like if I make an animation of the head going left and right I want the camera to rotate those ways too. Yet the code keeps giving me an error, help would be appreciated.
local runService = game:GetService("RunService")
local camera = game.Workspace.CurrentCamera
local character = game.Players.LocalPlayer.Character
runService.RenderStepped:Connect(function()
camera.CFrame.Rotation = character.Head.CFrame.Rotation
end)
local runService = game:GetService("RunService")
local camera = game.Workspace.CurrentCamera
local character = game.Players.LocalPlayer.Character
runService.RenderStepped:Connect(function()
character.Head.CFrame = CFrame.new(character.Head.Position, character.Head.CFrame.Rotation)
end)
That takes three numbers and makes a CFrame with identity rotation and those coordinates. I think I know what you mean though and it would be: camera.CFrame = character.Head.CFrame - character.Head.Position + camera.CFrame.Position
There’s not a very good constructor for this.
You can use CFrame.new() in so many ways, you can give 3 variables for positioning X, Y, Z or give two variable one Position and one Angle or just give it a Position…
You know what way the head orientation is facing, by taking the head’s orientation. Then just take the head’s lookvector, and make the camera’s orientation the same.
camera.CFrame = head.CFrame - head.CFrame.LookVector*20 -- 20 is the offset in studs, that the camera is away from the head.
CFrame.Rotation is a read-only property, as in it can only be read and not changed like that.
In order to get the rotation of a Cframe you need to use the CFrame:ToOrientation() function
local x, y, z = head.CFrame:ToOrientation() -- Returns the X, Y, Z values of the Rotation