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

How to attach a camera to a player head without using CameraType?

Asked by 6 years ago

Guys I have this script:

Camera.CameraType = Enum.CameraType.Scriptable
    Camera.CFrame = player.Character:WaitForChild("Head").CFrame
    Camera.Focus = CFrame.new(player.Character.Head.CFrame.lookVector)
    wait(1)
    player.Character:WaitForChild("Torso").CFrame = CFrame.new(player.Character.Torso.CFrame.p, Vector3.new(game.Workspace.Basement.JumpscarePart.Position.X, player.Character.Torso.CFrame.p.Y,game.Workspace.Basement.JumpscarePart.Position.Z))
    Camera.CFrame = CFrame.new(Camera.CFrame.p, Vector3.new(game.Workspace.Basement.JumpscarePart.Position.X,Camera.CFrame.p.Y,game.Workspace.Basement.JumpscarePart.Position.Z))
    --Play some scary aas sound here.
Camera.CameraType = Enum.CameraType.Attach--I don't want this

The problem is that I need a way to attach a camera to the head without using the attach method, because when I use it the camera goes dirrectly in 3rd person.

What I'm trying to do is make the camera attatched to the head so It follows the head movements in first person because when playing animations or anything the camera just stays in place. I already saw people do this but i have no idea how they did.

I apreciate any help!

0
That only makes the camera look at something. Not FOLLOW that thing. -.- wilsonsilva007 373 — 6y

1 answer

Log in to vote
0
Answered by 4 years ago

Based on your comment up above, what you could do is use :GetPropertyChangedSignal to check every frame if the camera has moved. When used in conjunction with RunService's RenderStepped you're unstoppable.

Here is an example for you.

local Camera = workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable
local subject = --part_instance or anything here
Camera.CameraSubject = subject

local function OnChanged()
    Camera.CFrame = subject.CFrame
end

game:GetService("RunService").RenderStepped:Connect(function()
    subject:GetPropertyChangedSignal("Position"):Connect(OnChanged)
    end
end)

A thing to note (which is a bit unrelated to this) is that if you are not making any expensive actions like camera changes, do not use RenderStepped for this. Instead, use Heartbeat, which can also return how much time has passed since every delta movement.

Ad

Answer this question