What does the camera look toward when it's subject is the player's humanoid?

I am making an NPC dialogue system, and after the end of conversation, I want to tween the camera back to the position it was in relative to the player.

When I start dialogue, I save the camera offset stuff relative to the head, and toggle the camera to scriptable. When it’s finished, I set the camera’s CFrame to the saved CFrame, and set the camera back to Custom.

However, the CFrame I saved is just slightly offset from the camera’s CFrame before the dialogue began.

This leads me to believe that the camera isn’t focusing on the head when it’s subject is the player’s humanoid, but is instead focusing slightly offset from the head.

Is there a way I can save this same exact position based on the humanoid’s weird phantom subject positioning?

1 Like

Why not just have it go back to custom once the dialogue is over? Is there a specific reason you saved the initial camera position/offset?

So I can tween back to it in a smooth fashion.

I’m not too sure if this will answer your question because I don’t know what direction the resulting camera is offset by, but when I tween back to the character I always set the subject to this:

distance = (camera.CFrame.Position - camera.Focus.Position).Magnitude
camera.CFrame = character.HumanoidRootPart.CFrame * CFrame.new(0, 1.5, distance)

It gives me the smooth tween that I need, the 1.5 that I am using may vary though if the NPC is not standard dimensions.

1 Like

Thats pretty close. The gap is smaller, but still a little off.

Are you using a default character, or a scaled character?

Scaled. I want a solution that will work with scaled characters as well.

I’m assuming you mean scaled R15.

I looked at the actual camera scripts, and this is what it says for camera offsets on characters.

local HEAD_OFFSET = Vector3.new(0,1.5,0)

local R15_HEAD_OFFSET = Vector3.new(0, 1.5, 0)

local R15_HEAD_OFFSET_NO_SCALING = Vector3.new(0, 2, 0)

What I would recommend is to look at the BodyProportionScale value under the humanoid, and if it is not the normal, use the scaling value, then if it is the normal, use the none scaling value.

1 Like

I tried using BodyHeightScale times 1.5 to see if that worked, but no dice. My avatar’s proportion scale is 0, but my other scaling is different.

EDIT: Tried multiplying that result by HeadScale to see if that would help. It’s just barely off.

That’s odd?

I went into studio and tried to replicate the slight offset you were talking about, but was unable to. I first tried it with a normal scaled character, and it tweened smoothly, I then tried it with a taller character and it still tweened smoothly. Go ahead and check out my code and see if it’s able to solve your problem.

local camera = game.Workspace.CurrentCamera

local character = game.Players.LocalPlayer.Character

function defaultCamera()
    camera.CameraType = Enum.CameraType.Custom
    camera.CameraSubject = character.Humanoid
    camera.FieldOfView = 70
end

function tweenCamera(cframe, timeElasped)
    local twi = TweenInfo.new(timeElasped, Enum.EasingStyle.Linear)
    game:GetService('TweenService'):Create(camera, twi, {CFrame = cframe, Focus = cframe}):Play()
    wait(timeElasped)
end

local distance

while wait(5) do
    distance = (camera.CFrame.Position - camera.Focus.Position).Magnitude
    camera.CameraType = Enum.CameraType.Scriptable
    tweenCamera(workspace.Part.CFrame, 1)
    wait(5)
    tweenCamera(character.HumanoidRootPart.CFrame * CFrame.new(0, 1.5, distance), 1)
    defaultCamera()
end

Tried to attach a video showing the results, couldn’t get it to upload, so hopefully you’re able to see it yourself.

Why do you need to know it’s position relative to the head? The head moves around and does animations which adds extra complexity.

I have a very similar system in a game I’m creating and I save the relative CFrame to the HumanoidRootPart:

StoredCframe = Camera.CFrame - HumanoidRootPart.CFrame.Position

and then when I’m done and want to tween back, I tween to

CFrame.new( StoredCframe + HumanoidRootPart.CFrame.Position, StoredCframe + StoredCframe.LookVector )
1 Like

ok u created the tweening script, when u want to return camera back to player just diseable the script using other script

Yeah, I had actually found this solution eventually on my own. I realized I was overcomplicating things.