#### Archived

This topic is now archived and is closed to further replies.

# xyz

This topic is 5239 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I like to know how to move an object from source to destination in xyz plane. To be more specific....... If I want to shoot an object the bullet path has to be calculated. I''m looking for a solution. thanks - Dhanyu

##### Share on other sites
Well, assuming nothing wacky, you''ll have a source vector and a destination vector, each with x, y, and z components. The displacement between the 2 (i.e. the difference) can be found by having a vector (vDestination - vSource).

You can derive a line equation from the start and end by determining slope in the x and z directions. This will probably be of the form y = f(x, z). If you have a velocity vector, you can also come up with a set of functions x = f(t), y = f(t), and z = f(t). These will give you a set of parametric equations that define your line. But generally the vector is enough, unless you need to do some sort of time based prediction or something.

That was kind of quick, if I lost you just say so.

##### Share on other sites
HI,

if source is X Y Z and destination is X1 Y1 Z1

displacement = X-X1, Y-Y1, Z-Z1

so if I move my object in loop till while
i != X-X1 i++ or i--
j != Y-Y1 j++ or j--
k != Z-Z1 k++ or k--

this would give me straight path to the destination.

this is what I understood. Thank you for your reply. Please let me know if I''m wrong.

- Dhanyu

##### Share on other sites
More or less, yeah. The only things to note:

i, j, and k are almost certainly floating point variables, so you can add something other than 1 to them, any number in fact (this is where a velocity vector comes in). Instead of checking i != X - X1 you should probably check that i < X - X1 or whatever, because there''s a possibility of overshooting the final target (floating point inaccuracies and such). Then when you do reach or pass the end point, set the coordinates to the end point. This will make sure you don''t overshoot your target.

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 23
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631766
• Total Posts
3002235
×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!