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)
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?
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
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?