I’m making an IFE for an airline and one of the features I wanted to add is a progress bar on how close the airplane is to the destination.
The issue I’m having is the position of the plane on the UI. I have got the percentage part right which ranges from 0 to 1. The thing I don’t know how to do now is to calculate the position on the UI.
I have tried to get the Positions of both UIs and find the magnitude between the UIs.
local DistanceBetween = (DestinationAriport.Position - StartingAirport.Position).Magnitude
local DistanceBetweenUI = (Menu.Airplanescene.END.AbsolutePosition - Menu.Airplanescene.START.AbsolutePosition).Magnitude
function PLanePositionLogic()
local PlayerDistance = (Player.Character.HumanoidRootPart.Position - StartingAirport.Position).Magnitude
local Percentage = math.clamp((PlayerDistance / DistanceBetween),0,1)
PlaneIcon.Position = UDim2.new(Percentage / DistanceBetweenUI ,0,0,0)
end
The X scale is 0-1, you are looking at absolute values which do not matter as the UI will automatically translate the UDim Scale into what ever size is needed.
In this sample if you set Frame.Plane.Position = UDim2.new(percent,0,0.5,0) you will get the results you want.