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

How do i calculate wind speed value trough distance?

Discussion in 'Scripting' started by odvigajlo123, Jun 13, 2022.

  1. odvigajlo123

    odvigajlo123

    Joined:
    May 27, 2020
    Posts:
    4
    Sooo i made simple script which calculates distance between cube and air plane, and now i need to get wind speed value with this (me struggling with this) Closer to cube higher wind speed, further lower

    Code (CSharp):
    1. float distance = Vector3.Distance(gameObject.transform.position, airCraft.transform.position);
    2.  
    3. weatherSystem.windSpeed = distance/windDistanceFallout;
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,964
    Airspeed is the relative difference between a moving object and the moving volume (fluid) that it is moving through.

    In actual aircraft this is determined by comparing the ram air pressure from the pitot tube with the static air pressure from the static source port.

    What exactly are you trying to do here with distance???
     
  3. odvigajlo123

    odvigajlo123

    Joined:
    May 27, 2020
    Posts:
    4
    I want to use distance for wind speed measure, like closer to cube higher wind speed, further lower wind speed. For Example: Right infront of cube wind speed will be 255 km/h, and some where at other end of map wind speed will be 0
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,964
    You could develop a function for that.

    Linear would be:

    var windspeed = MaxWind * (1 - Distance / MaxDistance);


    One-over might be:

    var windspeed = MaxWind / (BaseDistance + Distance * FalloffRate);


    The actual function for a given body passing through a fluid is entirely dependent on the shape of the body.

    Alternately you could use something like a public AnimationCurve lookup table to look it up, then just set the curve up however you like in the editor.
     
  5. odvigajlo123

    odvigajlo123

    Joined:
    May 27, 2020
    Posts:
    4
    Yes this works but if i far away from cube then return value goes negative, i need it to stay at 0
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,964
    Then don't let Distance get above MaxDistance!!
     
  7. odvigajlo123

    odvigajlo123

    Joined:
    May 27, 2020
    Posts:
    4
    I made that is wind speed is lower then 0 then set it to 0 and now works perfectly!