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

How would I create a custom camera that attaches to a player's head?

Asked by 6 years ago

It's pretty self explanatory. So far, I've slapped down this hastily made code into a StarterCharacter's animate script.

local UserInputService = game:GetService("UserInputService")
local Character = script.Parent
local cam = workspace.CurrentCamera
local deltax = 0
local deltay = 0
local pose = "Standing"

game:GetService("RunService").Heartbeat:Connect(function()
    if pose == "Running" and Character then
        if Character:FindFirstChild("Head") then
            cam.CFrame = CFrame.Angles() + Character.Head.CFrame.p --I don't know what to put here
        end
    end
end)

UserInputService.InputChanged:connect(function(inputObject)
    if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
        deltax = inputObject.Delta.x
        deltay = inputObject.Delta.y
    end
end)

--there's obviously more to the script, I just only put in what I'm using for this part

I want to make it so that the camera's position is attached to the head, but whenever the player moves their mouse (or whatever) they can still look around like in first person.

Problem is, I'm literally in middle school and have no idea how to convert 2D movement onto a 3D plane.

Any help?

1 answer

Log in to vote
0
Answered by 6 years ago

You can make the Camera be 1 stud in front of the Player's head by doing this.

cam.CFrame = Character.Head.CFrame * CFrame.new(0,0,1)

By setting the camera's CFrame to the Character's Head's CFrame you place them in exactly the same position and same rotation. When you want to add CFrames, you use multiply instead, so I'm effectively just adding 1 onto the Position of their head, you can change it and experiment to see what you like best.

For the camera looking like it's still in first person, that shouldn't happen anymore since it's being set to that position constantly.

I am 99% sure this will work :) If it doesn't you can shoot me a message and if I see it I'll answer it. (I'm not on scripting helpers much)

0
Oh, I meant I WANT it to move like a first person camera. I don't want to fixate the camera COMPLETELY to the head, rotation and all. steven73598233 75 — 6y
0
Welp. I can't answer that, I haven't done it before but I know it includes welding and things like that. You should look at some free models and see how they work if nobody has the answer here. Shadi432 69 — 6y
Ad

Answer this question