Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Flight Time Algorithm

Discussion in 'Scripting' started by kraziion, Nov 26, 2016.

  1. kraziion

    kraziion

    Joined:
    Nov 11, 2016
    Posts:
    17
    Hey guys i know this isnt the place for this kinda stuff but maybe someone could help xD

    basically i have to make a simple flight time calc which will take in the details;

    Departure place/town •
    Arrival place/town •
    Date and Time of departure •
    Date and Time of arrival to the destination (local time) •
    Time difference between departing place and arrival place •

    This is pretty simple, but i cant wrap my head around how to make it consider the fact that you can travel a date backwards. I dont need code i need an algorithm xD

    so what i would do normally is convert time to UTC neutral and then do dep - arrival. but if the date goes back it doesnt work.
     
  2. magnite

    magnite

    Joined:
    Dec 12, 2012
    Posts:
    125
    What is wrong with the good old formula: Time = Distance * Rate? Add on any complications such as weather.

    Add this to your Arrival local time to get your real arrival time.
     
  3. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    flight duration = arrival time - ( departure time + [time difference])

    time difference is [zone at arrival - zone at take off]

    eg. you take off in UTC+0 (London) at 10.00
    you land in UTC +3 (Moscow) at 17.00
    Code (CSharp):
    1. time = 17 - (10 +[+3 -  +0])  
    2. = 17 - 13
    3. = 4 hours
    eg. you take off in UTC+9 (Tokyo) at 14.00
    you land in UTC -8 (LA) at 09.00 earlier in the same day
    (Crossing the date line)
    Code (CSharp):
    1. time = 9 - ( 14 + [-8 - +9])
    2. = 9 - (14 + -17)
    3. = 9 - -3
    4. = 12 hours
    I think
     
  4. kraziion

    kraziion

    Joined:
    Nov 11, 2016
    Posts:
    17
    ye
    ah theres a tons of post about that ;d but the thing is it doesnt require and distance and weather calculations. All it needs is to calc the flight duration. The user enters the date and time or arival/departure and how long the flight takes. it just needs to be a formula to show how it works to get the flight time i guess? xD i know its stupid. But its part of a pointless assignment.