Camera and Root part Direction

:warning: WARNING I understand this is very difficult to accomplish so any help is appreciated!

Hello I was wondering how can I figure out where I’m pointing at the player? Am I pointing at it’s side at the front? I need this because I’m making a camera delay system and it works in shift lock since it’s using humanoid move direction, but when I don’t have mouse lock it zooms in instead since it’s thinking the player is going straight.
Here’s the script if needed:

local character = script.Parent
local rootPart = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")

local weight = 1.75
local t = 10

function cardinalConvert(dir)
	local angle = math.atan2(dir.X, -dir.Z)
	local quarterTurn = math.pi / 2
	angle = -math.round(angle / quarterTurn) * quarterTurn

	local newX = -math.sin(angle)
	local newZ = -math.cos(angle)
	if math.abs(newX) <= 1e-10 then newX = 0 end
	if math.abs(newZ) <= 1e-10 then newZ = 0 end
	return Vector3.new(newX, 0, newZ)
end

function directionChanged(dt)
	if humanoid.MoveDirection ~= Vector3.new(0, 0, 0) then
		local humanoidVector = cardinalConvert(humanoid.MoveDirection)
		if humanoidVector.X == 0 then
			humanoidVector = Vector3.new(humanoidVector.X, 0, humanoidVector.Z * -1)
		elseif humanoidVector.Z == 0 then
			humanoidVector = Vector3.new(humanoidVector.X * -1, 0, humanoidVector.Z)
		end
		
		humanoidVector *= Vector3.new(weight, weight,weight)
		
		humanoid.CameraOffset = humanoid.CameraOffset:Lerp(humanoidVector, (1-dt)/t)
		print(humanoidVector)
	else
		humanoid.CameraOffset = humanoid.CameraOffset:Lerp(Vector3.new(0, 0, 0), (1-dt)/t)
	end
end


game:GetService("RunService").RenderStepped:Connect(directionChanged)

Picture:

Ideas: Could I maybe have a raycast?

Thank you.

I don’t understand what you mean by “I’m pointing at the player”

I meant like what direction my camera is pointing at if that makes sense. I’m looking into this topic I just found hopefully it will help.

This is kind of what I’m looking for, but I still need help.

I’m not too sure about this but you could maybe use the CurrentCamera’s Orientation to know what approximate position your camera is at?

1 Like

Hmm, seems like a good idea. Now the question is how do I apply this to my current script? It uses humanoid move direction so it’s vector3 so maybe move direction is not the answer. I’m going to experiment with this script:

1 Like