Ok really simple question for you guys, but I just can't figure out the best way to handle this. I've done plenty of 2d pathfinding but apprently it's kind of difference when you toss that Z in there.
So, 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
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. :)