12 Jul, 2009, quixadhal wrote in the 2nd comment:

If you're using a weighted graph pathfinding algorithm (such as A*), you just have to assign weights appropriately, the space you're moving through doesn't actually matter.

If distance is your only weight, then yes, a straight line is probably just fine.

So, given points P (20,20,20) and Q (50,50,50), you compute a directional vector as V (Qx-Px, Qy-Py, Qz-Pz) = (30,30,30)

Then your equation is

x = Px + Vx(t)

y = Py + Vy(t)

z = Pz + Vz(t)

or

x = 20 + 30t

y = 20 + 30t

z = 20 + 30t

So, now you just have to bounds check to make sure you're inside the segment between the two points.

t = 0.0 is your origin (P), t = 1.0 is your destination (Q).

You might want to have a real math person check that… math and I don't often get along. :)

If distance is your only weight, then yes, a straight line is probably just fine.

So, given points P (20,20,20) and Q (50,50,50), you compute a directional vector as V (Qx-Px, Qy-Py, Qz-Pz) = (30,30,30)

Then your equation is

x = Px + Vx(t)

y = Py + Vy(t)

z = Pz + Vz(t)

or

x = 20 + 30t

y = 20 + 30t

z = 20 + 30t

So, now you just have to bounds check to make sure you're inside the segment between the two points.

t = 0.0 is your origin (P), t = 1.0 is your destination (Q).

You might want to have a real math person check that… math and I don't often get along. :)

12 Jul, 2009, Chris Bailey wrote in the 3rd comment:

Thanks Quix, coming along just fine now =)

12 Jul, 2009, Idealiad wrote in the 4th comment:

http://www.ies.co.jp/math/java/vector/ch...

http://www.geocities.com/SiliconValley/2...

http://members.tripod.com/~Paul_Kirby/ve...

http://www.flipcode.com/archives/3D_Geom...

http://www.gamedev.net/community/forums/...

http://lmgtfy.com/?q=formula+of+line+3D :rolleyes:

*eta*: quix beat me to the finish there ;D

http://www.geocities.com/SiliconValley/2...

http://members.tripod.com/~Paul_Kirby/ve...

http://www.flipcode.com/archives/3D_Geom...

http://www.gamedev.net/community/forums/...

http://lmgtfy.com/?q=formula+of+line+3D :rolleyes:

Random Picks

0.0/4

Votes:0So, I have an object at location 20,20,20. It's current destination is 50,50,50. Barring any physical obstructions along the way, how do you calculate

the path that the object must take to reach it's destination? My idea was to draw a line from point A to point B, toss the coordinates (in order) into

an array and travel along them when the time came to move…but I don't know how to mathematically draw that line :P