So I’ve been trying to make this off-screen ship indicator which basically tells you the position of the ship, but for some reason when you turn away from the ship, the indicator shows up in front of you instead of on the sides.
https://gyazo.com/8e1832a4dbaf08dbcb27cc3eb69ba810
Script:
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local Viewport = script.Parent:WaitForChild("ShipViewport")
local ShipViewport = Viewport:WaitForChild("ShipViewModel")
local RealShip = workspace:WaitForChild("Cutter")
local RealShipSeat = RealShip:WaitForChild("BoatSeat")
local ShipDescendants = RealShip:GetDescendants()
RealShip.DescendantAdded:Connect(function(v)
table.insert(ShipDescendants, v)
end)
RealShip.DescendantRemoving:Connect(function(v)
local Found = table.find(ShipDescendants, v)
ShipDescendants[Found] = nil
end)
local Camera = workspace.CurrentCamera
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local clamp = math.clamp
local rad = math.rad
RunService:BindToRenderStep("SetCirclePos", Enum.RenderPriority.Camera.Value, function(dT)
if not ShipViewport.PrimaryPart or not Character.PrimaryPart then return end
local Scale = dT * 60
local ShipVectorMath = RealShipSeat.Position + (RealShipSeat.CFrame.LookVector * 35)
local CFPos = CFrame.new(ShipVectorMath, Character.PrimaryPart.Position)
local PosMath = ShipViewport.PrimaryPart.Position + CFPos.LookVector
ShipViewport:SetPrimaryPartCFrame(CFrame.new(ShipViewport.PrimaryPart.Position, Vector3.new(PosMath.X, ShipViewport.PrimaryPart.Position.Y, PosMath.Z)) * CFrame.Angles(0, rad(180), 0))--CFPos.Position))
local RayShoot = Ray.new(Camera.CFrame.Position, Camera.CFrame.LookVector * 2048)
local Hit = workspace:FindPartOnRayWithWhitelist(RayShoot, RealShip:GetDescendants())
local Vector, OnScreen = Camera:WorldToScreenPoint(ShipVectorMath)
local VectorMath = Camera.ViewportSize - script.Parent.AbsoluteSize
local Vector2Pos = Vector2.new(clamp(Vector.X, 0, VectorMath.X), clamp(Vector.Y, 0, VectorMath.Y))
local LerpAbsPos = script.Parent.AbsolutePosition:Lerp(Vector2Pos, .1 * Scale)
script.Parent.Position = UDim2.new(0, LerpAbsPos.X, 0, LerpAbsPos.Y)
if OnScreen and Hit then
if Hit:IsDescendantOf(RealShip) then
script.Parent.Visible = false
return
end
end
script.Parent.Visible = true
end)
Any help is appreciated.