CFrame.lookAt isn't working with what I am doing

I wanted to make a Death Camera which looks at the player while he dies.

My issue is that the camera succesfully fix it self but doesn’t follow the HRP and I doesn’t understand why…
I have already tried to use differents CFrame settings but not working.

Here a video:
streamable video

--// Références
local GameFolder = game:GetService("ReplicatedStorage"):WaitForChild("Game", 3000)
local NetworkingFolder = GameFolder:WaitForChild("Networking", 3000)
local Interface = game:GetService('SoundService'):WaitForChild('Interface')

--// Modules
local Events = require(NetworkingFolder.Events)

--// Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

--// Références
local LocalPlayer = Players.LocalPlayer
local Camera = workspace.CurrentCamera


--// Controls
local Controls = require(LocalPlayer:WaitForChild("PlayerScripts", 3000):WaitForChild('PlayerModule', 3000)):GetControls()

local spectating
Events.Player.onDeath_Remote.OnClientEvent:Connect(function()
	local fixedPosition = Camera.CFrame.Position + Vector3.new(0, 5, -10)
	--local Part = Instance.new('Part')
	
	--Part.Name = LocalPlayer.Name
	--Part.Transparency = 1
	--Part.Parent = workspace.DeathsCameras
	
	repeat Camera.CameraType = Enum.CameraType.Scriptable until Camera.CameraType == Enum.CameraType.Scriptable
	--Camera.CFrame = Part.CFrame
	
	spectating = RunService.RenderStepped:Connect(function()
		local targetPos = LocalPlayer.Character.HumanoidRootPart.Position
		if targetPos then
			Camera.CFrame = CFrame.new(fixedPosition, targetPos)
		end
	end)
end)

LocalPlayer.CharacterAdded:Connect(function()
	if spectating then
		spectating:Disconnect()
		spectating = nil
	end
	Camera.CameraType = Enum.CameraType.Custom
end)

The code looks fine at first glance. Try printing targetPos every frame. It will help locate the source of the problem.

1 Like

Ok, I retried it and I just found out that yea, that’s the issue…
here’s the result :

  17:46:53.284  -12.088322639465332, -22.484355926513672, 19.500228881835938  -  Client - DeathCameraManager:36
  17:46:53.295  -12.239936828613281, -24.414249420166016, 19.53614616394043  -  Client - DeathCameraManager:36
  17:46:53.301  -12.343361854553223, -25.658876419067383, 19.49323844909668  -  Client - DeathCameraManager:36
  17:46:53.311  -12.353758811950684, -26.292470932006836, 19.488239288330078  -  Client - DeathCameraManager:36

The video showing it ( it video is too fat )

Alright, it seems like the position of the HumanoidRootPart is not changing. Not sure if this will work, but try following the position of the Head instead.

1 Like

Perfect, it worked correctly, maybe the ragdoll was just locking in place the HumanoidRootPart.
Thank you.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.