Home   Help Search Login Register  

Author Topic: Distance calculation between objects  (Read 1460 times)

0 Members and 1 Guest are viewing this topic.

Rimak

  • Guest
Distance calculation between objects
« on: 29 Aug 2002, 11:07:10 »
Hello ppl,

The problem is:
We have a chopper hovering in the air and soldier standing on the roof of a building.

The question:
How to calculate real distance between these two units? Simply using 'distance' gives incorrect result. Because Y coord (height) of a unit standing on a roof is wrong as if it were standing on the ground. Any solutions?

P.S. When climbing the ladder Y coordinate is correct and shows the real unit height above the ground.

Pope_Zog

  • Guest
Re:Distance calculation between objects
« Reply #1 on: 29 Aug 2002, 13:26:34 »
Use Pythagoras' theorem. Like so:

              + Heli1
             /|
 Distance - / | - Vertical distance
           /  |
 Soldier1 +---+
            |
    Horizontal distance

Distance^2 = (Vertical Distance)^2 + (Horizontal Distance)^2

Code: [Select]
; The square of the distance between the two is the square of the horizontal distance plus the square of the vertical distance

_distanceHorizontal = Soldier1 distance Heli1;
_distanceVertical = abs (getPos Soldier1 select 2 - getPos Heli1 select 2);
_distance = sqrt (_distanceHorizontal * _distanceHorizontal + _distanceVertical * _distanceVertical)

Pope Zog

Rimak

  • Guest
Re:Distance calculation between objects
« Reply #2 on: 30 Aug 2002, 00:38:59 »
It is not so simple. The problem is that i can't get 'real' vertical distance when soldier is standing on the roof of the building. Game reports that the soldier's altitude is ~0 and the real altitude can be 15 or 20.

Offline toadlife

  • OFPEC Old Skool
  • Former Staff
  • ****
  • Official OFP Editing Center Toad
    • toadlife.net
Re:Distance calculation between objects
« Reply #3 on: 30 Aug 2002, 01:54:13 »
Try placing a gamelogic unit at the position of the soldier and then querying the distance between the gamelogic and the soldier. A gamelogic is allway 0m above ground. Something tells me it wont work but its worth a shot.
"Whenever you want information on the 'net, don't ask a question; just post a wrong answer." -- Cancer Omega.