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

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

Asked by
Galicate 106
6 years ago
Edited 6 years ago

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

Log in to vote
1
Answered by 6 years ago

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)
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. Galicate 106 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
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

Answer this question