How do I make my camera point straight infront of my HRP

Hey,
Just want guidance on how to have my camera point straight infront of my humanoid root part in the middle of the screen.
Appreciate any help.

1 Like
local hrpCFrame = LocalPlayer.Character.HumanoidRootPart.CFrame

Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = CFrame.new((hrpCFrame * CFrame.new(0, 0, -5)).Position, hrpCFrame.Position)

Sorry, I meant to say point directly forward in first person.

local hrpCFrame = LocalPlayer.Character.HumanoidRootPart.CFrame

Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = CFrame.new(hrpCFrame.Position, hrpCFrame.Position.LookVector)

getting error from .LookVector.

Oops mb.

Camera.CFrame = CFrame.new(hrpCFrame.Position, hrpCFrame.LookVector)

It is staying with the body but the camera stays at the spawn.

while true do
	local Camera = game.Workspace.CurrentCamera

	local hrpCFrame = plr.Character.HumanoidRootPart.CFrame

	Camera.CameraType = Enum.CameraType.Scriptable
	Camera.CFrame = CFrame.new(hrpCFrame.Position, hrpCFrame.LookVector)
	wait()
end

Could you elaborate better please? Also, hook the code to a RunService.RenderStepped function than a while loop.

2 Likes

robloxapp-20230704-1719534.wmv (1.0 MB)

1 Like

I’m sry but I don’t see any problem…

cframe it with upper torso or smth hrps dont really move the same your char moves

Hey, i have edited your code.
You were missing with the calculated position that is LookVector of the HumanoidRootPart added by a Position of the HumanoidRootPart. Also, do not use while true do in the local script because it loops the code without any simulation to be completed or started so this is laggy way.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:FindFirstChildOfClass("Humanoid")
local hrp = player.Character:WaitForChild("HumanoidRootPart")

local Camera = game.Workspace.CurrentCamera
Camera.CameraType = Enum.CameraType.Scriptable
local RS = game:GetService("RunService")

RS.Heartbeat:Connect(function()
	Camera.CFrame = CFrame.new(hrp.Position, hrp.Position + hrp.CFrame.LookVector)
	wait()
end)

I think, this is your expected result:

3 Likes

thanks bro, appreciate the help.

1 Like

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