I am currently working on a driving game, and I would like to make a viewportframe compass that points to a destination so that the player knows the general direction in which he/she/they must head toward. Currently, I have a script that does point in the general direction. However, the arrow’s head seems slightly off. It often points too high.
This is my code so far:
local plr = game.Players.LocalPlayer
local cam = Instance.new("Camera", script.Parent)
local part = script.Parent.Part
script.Parent.CurrentCamera = cam
game:GetService("RunService").RenderStepped:Connect(function()
if game.Workspace:FindFirstChild(plr.Name.."Hitbox") and plr.Character.Humanoid.Sit and plr:FindFirstChild("Truck") then
cam.CFrame = game.Workspace.CurrentCamera.CFrame
part.CFrame = CFrame.new(plr.Truck.Value.Body.Windshield.CFrame * CFrame.new(0,2,0).Position,
Vector3.new(game.Workspace:FindFirstChild(plr.Name.."Hitbox").Position.X,
game.Workspace:FindFirstChild(plr.Name.."Hitbox").Position.Y - 10,
game.Workspace:FindFirstChild(plr.Name.."Hitbox").Position.Z))*CFrame.Angles(math.rad(90),math.rad(180),-math.rad(90))
end)
I am almost certain that the issue is occuring because the fact that the arrow is offset relative to the camera, but I can’t come up with a solution. I have already tried playing with the degrees of the angles, and obviously that didn’t work.