Page 1 of 1

Distance to horizon

PostPosted: Sun Jun 24, 2007 12:09 am
by jlorinser
Hi,

I'm trying to calculate the distance between 2 actors in a simulated 3D environment. An enemy starship comes at the player's ship (located at the bottom of the screen) from the "horizon" (located roughly at 1/4 of the screen height from the top) towards the player.

I´m moving the enemy starship slower at the horizon and speeding it as it moves to the bottom of the screen using:

Code: Select all
MoveTo("Enemy", 0, 0, (Enemy.y / 600) * 2, "Player", "");

and this works well to create the illusion of depth, but the distance is ovbiously also decreased at the speed of movement.

I tried using the distance function, but the problem is that it calculates the distance linearly and thus the enemy starship does not "cover more space" (per pixel moved on the y axis) at the top of the screen than what it does almost at the bottom.

I'm stuck at this point :x . Anyone have a solution?

Thanks in advance

PostPosted: Tue Jun 26, 2007 11:52 am
by metal_pt
Hmmm.

What about creating a Z variable?
the real distance could be something like:
realdistance=sqrt(pow(distance(x, y, enemy.x, enemy.y),2)+pow(Z,2));

Best regards

PostPosted: Thu Jun 28, 2007 7:43 pm
by jlorinser
Thanks metal_pt,

What would the value of Z be? would it be the distance traveled (starting from horizon)?

Thanks again...

PostPosted: Thu Jun 28, 2007 8:03 pm
by metal_pt
Well, in my mind, z should be the virtual depth of the ship.