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.