Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How could I make it so that the players camera it always facing the direction a part is?

Ok so I know how to do camera manipulation. But how can I make it so that a Scriptable CameraType follows the direction the players head faces(I have a head turning script.)

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Camera = workspace.CurrentCamera
repeat wait()
	Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
Camera.CFrame = Character.Head.CFrame

2 answers

✓ Accepted answer

Try this:

local offset = Vector3.new.new(0,0,5) -- Offset from the player's Head
local camera = workspace.CurrentCamera
local RS = game:GetService('RunService')

RS:BindToRenderStep('Bind', Enum.RenderPriority.Camera.Value, function()
        camera.CameraType = Enum.CameraType.Scriptable
        camera.CFrame = Character.Head.CFrame+offset
end)

1 comment

0

Yes thats what Im looking for. I noticed that on line 1 you said vector3.new.new lol. My only problem with this is that my head turn script doesnt work with it.

local function GetAngle(HumanoidRootPart,Camera)
    local adjustedVector = HumanoidRootPart.CFrame:vectorToObjectSpace(Camera.CFrame.lookVector) -- convert the camera's lookVector into object space so that we know which way the camera is pointing relative to the part the head rotates around
    local actualAngle = math.atan2(-adjustedVector.X,-adjustedVector.Z) -- this combination will turn the LHR coordinate system into a RHR angle
    return actualAngle
end

https://devforum.roblox.com/t/how-to-make-head-turn-to-cameras-lookvector-direction/99007/3

This discussion is preserved as it was. New answers, comments, and votes are closed.