Results 1 to 9 of 9

Thread: Distance between two actors

  1. #1
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Distance between two actors

    So, I'm back with more questions if someone can help at all please (sorry).

    I can get the x, y and z of an actor from the Pos()

    and elsewhere I've used getNearestEnemyGroup etc which assesses the distance between airgroups and the player and returns the one with the lowest....

    But what I can't figure out is if there is an easy way to return the distance in metres between two Pos(), either 3d , or just x and y.

    Peeking at the code I see various things relating to distance, but too many to immediately understand what is what and what I should be focusing on. And I saw someone seemingly working out trignonometry values, is this still necessary?

    I'm hoping there is some way to simply call a method and give it the ref/from and it will politely return the distance in metres for me....

    At the moment I am looking to get the nearest enemy airgroup (which I can do) but then also return the distance to it in metres?
    I am Yo-Yo not YoYo (that's someone else)

  2. #2
    Supporting Member
    Join Date
    Oct 2020
    Posts
    196
    Post Thanks / Like
    Total Downloaded
    197.43 MB

    Re: Distance between two actors

    aircraftPlayer is a maddox.game.world.AiAircraft : this is the aircraft of the player
    actorCible is a maddox.game.world.AiActor : this is the target AiActor

    This calculate
    relative distance : distanceSol (X, Y only)
    Absolute distance : distanceAbs (altitude is taken in count)
    relative angle : angleSol (X, Y only). If less than 0 means the player is in front of the target.
    elevation angle : angleElevation

    Code:
    			// get positions chasseur et cible
                            const double DegRad = 57.295779513082321;  // (180 / PI)
    			double positionX1 = aircraftPlayer.Pos().x;
    			double positionY1 = aircraftPlayer.Pos().y;
    			double positionZ1 = (double)((int)(aircraftPlayer.Pos().z * 10)) / 10; // precision +- 0.1 mètre
    			double positionX2 = actorCible.Pos().x;
    			double positionY2 = actorCible.Pos().y;
    			double positionZ2 = (double)((int)(actorCible.Pos().z * 10)) / 10;	
    			double deltaX = positionX2 - positionX1;  // si > 0 la cible est à droite
    			double deltaY = positionY2 - positionY1;  // si < 0 la cible est derrière
    			double deltaZ = positionZ1 - positionZ2;
    			double distanceSol = Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY));  // distance au sol
    			double distanceAbs = Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY) + (deltaZ * deltaZ));  // distance absolue (on tient compte de l'alti)
    			double angleSol = Math.Asin(deltaY / distanceSol) * DegRad;  // si < 0 chasseur devant
    			double angleElevation = Math.Asin(deltaZ / distanceSol) * DegRad;  // calcul Elevation
    Hope that helps
    Last edited by Sleepy_Fly; Mar-19-2023 at 15:40.
    "You can teach monkeys to fly better than that!"

    Win 11 Pro - I5-12600KF - 32GB Ram - RTX 3080 TI 12GB (non OC) - SSD Sata 970 GBB (System) - NVMe 980 GB (games storage) - Lenovo 27'' 144Hz - HP Reverb G2 v2 -
    WMR environment : Empty room (SkySpaces) - SteamVR resolution : 2192x2144 (48%)
    nVidia driver : 536.23

  3. #3
    ATAG Member ATAG_Oskar's Avatar
    Join Date
    Nov 2017
    Location
    Canada
    Posts
    986
    Post Thanks / Like
    Total Downloaded
    908.31 MB

    Re: Distance between two actors

    double dist = pointA.distance(ref pointB);

  4. Likes Yo-Yo liked this post
  5. #4
    Supporting Member
    Join Date
    Oct 2020
    Posts
    196
    Post Thanks / Like
    Total Downloaded
    197.43 MB

    Re: Distance between two actors

    Quote Originally Posted by ATAG_Oskar View Post
    double dist = pointA.distance(ref pointB);
    Is this method return relative or absolute distance ?
    "You can teach monkeys to fly better than that!"

    Win 11 Pro - I5-12600KF - 32GB Ram - RTX 3080 TI 12GB (non OC) - SSD Sata 970 GBB (System) - NVMe 980 GB (games storage) - Lenovo 27'' 144Hz - HP Reverb G2 v2 -
    WMR environment : Empty room (SkySpaces) - SteamVR resolution : 2192x2144 (48%)
    nVidia driver : 536.23

  6. #5
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: Distance between two actors

    Great thanks, I'll have a play around.
    I am Yo-Yo not YoYo (that's someone else)

  7. #6
    Combat pilot
    Join Date
    Oct 2021
    Posts
    113
    Post Thanks / Like
    Total Downloaded
    12.95 MB

    Re: Distance between two actors

    Deleted by GANIX
    Last edited by GANIX; Jun-04-2023 at 06:23.

  8. #7
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: Distance between two actors

    Quote Originally Posted by Sleepy_Fly View Post
    Is this method return relative or absolute distance ?
    Absolute by the looks of it from testing , but then I gave it 3d points....
    I am Yo-Yo not YoYo (that's someone else)

  9. Likes Sleepy_Fly liked this post
  10. #8
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: Distance between two actors

    Quote Originally Posted by ATAG_Oskar View Post
    double dist = pointA.distance(ref pointB);
    Thanks, worked easily enough after I realised I needed to give it a variable as the ref.
    I am Yo-Yo not YoYo (that's someone else)

  11. #9
    Supporting Member
    Join Date
    Dec 2019
    Posts
    473
    Post Thanks / Like
    Total Downloaded
    22.61 MB

    Re: Distance between two actors

    Quote Originally Posted by Sleepy_Fly View Post
    aircraftPlayer is a maddox.game.world.AiAircraft : this is the aircraft of the player
    actorCible is a maddox.game.world.AiActor : this is the target AiActor

    This calculate
    relative distance : distanceSol (X, Y only)
    Absolute distance : distanceAbs (altitude is taken in count)
    relative angle : angleSol (X, Y only). If less than 0 means the player is in front of the target.
    elevation angle : angleElevation

    Code:
    			// get positions chasseur et cible
                            const double DegRad = 57.295779513082321;  // (180 / PI)
    			double positionX1 = aircraftPlayer.Pos().x;
    			double positionY1 = aircraftPlayer.Pos().y;
    			double positionZ1 = (double)((int)(aircraftPlayer.Pos().z * 10)) / 10; // precision +- 0.1 mètre
    			double positionX2 = actorCible.Pos().x;
    			double positionY2 = actorCible.Pos().y;
    			double positionZ2 = (double)((int)(actorCible.Pos().z * 10)) / 10;	
    			double deltaX = positionX2 - positionX1;  // si > 0 la cible est à droite
    			double deltaY = positionY2 - positionY1;  // si < 0 la cible est derrière
    			double deltaZ = positionZ1 - positionZ2;
    			double distanceSol = Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY));  // distance au sol
    			double distanceAbs = Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY) + (deltaZ * deltaZ));  // distance absolue (on tient compte de l'alti)
    			double angleSol = Math.Asin(deltaY / distanceSol) * DegRad;  // si < 0 chasseur devant
    			double angleElevation = Math.Asin(deltaZ / distanceSol) * DegRad;  // calcul Elevation
    Hope that helps
    Yes, I will try that too as relative distance would be useful for me too.
    I am Yo-Yo not YoYo (that's someone else)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •