OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Rimak on 29 Aug 2002, 11:07:10

Title: Distance calculation between objects
Post by: Rimak 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.
Title: Re:Distance calculation between objects
Post by: Pope_Zog 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
Title: Re:Distance calculation between objects
Post by: Rimak 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.
Title: Re:Distance calculation between objects
Post by: toadlife 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.