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?
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:
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.
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.