Positioning a camera to in front of the head in a viewport and make it face the opposite of the head so that it shows the player's face?

Hello, I’ve been trying to create a viewportframe that shows the player’s head in the game. My issue is the camera doesn’t try to position itself according to where the head actually is facing, but rather is just position itselfs to the head. I want the camera to be positioned in front of the head and faces oppositely according to where the head was facing when a character is cloned inside the viewport. This is my current code:

view.CurrentCamera = Camera
local wm = Instance.new("WorldModel")
wm.Parent = view
task.wait(1)

local clone = char:Clone() --plr's character
clone.Parent = wm

char.Archivable = false


Camera.CFrame = CFrame.lookAt(clone.PrimaryPart.Position + Vector3.new(0.5,0,-5),clone.PrimaryPart.Position)
2 Likes
view.CurrentCamera = Camera
local wm = Instance.new("WorldModel")
wm.Parent = view
task.wait(1)

local clone = char:Clone() --plr's character
clone.Parent = wm

char.Archivable = false


Camera.CFrame = CFrame.lookAt(clone.PrimaryPart.Position + Vector3.new(0.5,0,-5),clone.PrimaryPart.Position)

Camera.CFrame *= CFrame.Angles(math.rad(180), 0, 0)

The character does not show up on my viewportframe after that code

Can you record a video and send it before and after the changes then? Easier to help that way.

B4 changes:
https://gyazo.com/4980875c66da8f869c51e2e03f2a96c5
After changes:
https://gyazo.com/cde1368140c4222a1a5ac9901c65a553
On the b4 changes you can see the port changing the character’s facing direction, I wanna fixate it like before resetting
I can kinda see the problem here, it’s that the camera isn’t adjusting to the player’s look direction but idk how to fix this lol

view.CurrentCamera = Camera
local wm = Instance.new("WorldModel")
local RunService = game:GetService("RunService")
wm.Parent = view
task.wait(1)

RunService.Heartbeat:Connect(function()
   Camera.CFrame = CFrame.lookAt(char.PrimaryPart.Position + Vector3.new(0.5,0,-5),char.PrimaryPart.Position)
end)

Can you try running this and see what that looks like?

https://gyazo.com/88278957bbe82b709825be990f363d89
Was kinda weird ngl, I think it’s got smth to do with the origin point of workspace

So what this is doing is updating your camera position every “heartbeat”, it’s a function within roblox and I think it can be useful for what you’re trying to do. Now, as I understand, you want your character to always look at the camera. Like, the camera will always be positioned in front ofthe player’s head?

I want the camera to forever just position in front of the player’s head, so that it can show the plrs face yea. you got it correct

Alright, let’s try adding the angles back and see what that does.

RunService.Heartbeat:Connect(function()
   Camera.CFrame = CFrame.lookAt(char.PrimaryPart.Position + Vector3.new(0.5,0,-5),char.PrimaryPart.Position)
   Camera.CFrame *= CFrame.Angles(math.rad(180), 0, 0)
end)

The chaaracter disappears completely like the above example after adding the line

view.CurrentCamera = Camera
local wm = Instance.new("WorldModel")
local RunService = game:GetService("RunService")
wm.Parent = view
local torso = char:WaitForChild("HumanoidRootPart")
task.wait(1)

RunService.Heartbeat:Connect(function()
   Camera.CFrame = torso.CFrame * CFrame.new(0,0,-10) * CFrame.angles(0, 0, math.rad(180))
end)

Try this instead, let’s see what happens.

local view = script.Parent
local Camera = Instance.new("Camera")
Camera.Parent = view
view.CurrentCamera = Camera
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
char.Archivable = true
local wm = Instance.new("WorldModel")
wm.Parent = view
task.wait(1)

local oldFrame = char.PrimaryPart.CFrame
local clone = char:Clone() --plr's character
task.wait(1)
clone.Parent = wm
char.Archivable = false
local torso = char:WaitForChild("HumanoidRootPart")


game:GetService("RunService").Heartbeat:Connect(function()
	Camera.CFrame = torso.CFrame * CFrame.new(0,0,-10, math.rad(180), 0, 0)
	--Camera.CFrame *= CFrame.Angles(math.rad(180), 0, 0)
end)

https://gyazo.com/d55a249085d64f9ae9abd18170b6938b
Here’s a clip and the full code too if that helps, I prolly messed up somewhere within it. I think I’m supposed to refer to torso as the cloned character n not the original but idk, when I tried that it didn’t work either

No this is fine, but there’s no need to reset your character. Just try doing everything we did without resetting, and the Heartbeat function should look like this

RunService.Heartbeat:Connect(function()
   Camera.CFrame = torso.CFrame * CFrame.new(0,0,-10) * CFrame.angles(0, 0, math.rad(180))
end)

https://gyazo.com/63c0194cb4c600e2fc3bcaee1f49276d
It’s still met with the same issue. Maybe I can try saving the original position of the character when they’re added with oncharacteradded, then apply that relative to the camera?

Took me long enough bruh ive finally found a solution

local torso = clone:WaitForChild("HumanoidRootPart")
local pos = torso.Position + torso.CFrame.LookVector*5 
Camera.CFrame = CFrame.new(pos,torso.Position)

ty for your help

2 Likes

Ah awesome, sorry I got busy in the meantime and didn’t get to respond! Glad you figured it out!

1 Like