Jump to content
  • Advertisement
Sign in to follow this  
teel

How to store the path the object should follow?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, First, hello everyone! :) I'm a newbie to game development but not programming in general, it's rather lack of game practices experience. I'm trying to make an Android game (Java) and have a couple of object that I want to follow predefined paths. The paths are lines, curves and a mixture of them. I'm thinking of two solutions of path info storage: 1) array of x y coordinates for each point of the path. This seems to me to be too inelegant and not effective. Let's say the path is 1000px long then it's 1000 x 2 x 2 bytes = 4kB for path info, too much I guess but no calculation is required; 2) specify a couple of fixed points and use a polynomial interpolation to generate path, then in each game life step (how is that called?) calculate the next position of object. This requires minimal data but requires calculation. Are there other methods to do it?

Share this post


Link to post
Share on other sites
Advertisement
Go for #2. If you're worried about performance, run some stress-tests with various interpolation methods to see how far you can push it. You could also look into steering behaviors.

Share this post


Link to post
Share on other sites
Ok, I also prefer #2 but still have a problem. I tailored my idea a bit but anyway I'm limited with my lack of experience in this matter.
I don't want the solution, just please help me start with a hint :-)

Let's say I want my object move the Z-shaped path (sharp corners are acceptable for start) just like a train on a rail, no matter the velocity and acceleration (they may change), it must follow the fixed path. The Z shape is not a function from the math perspective, so there is nothing to be done for polynomial interpolation unless I cut the shape into proper math functions, but this is way more complicated.

I'd like to start the path calculation from the fact that the Z shape can be described by 4 points, then linking them by 3 lines. Ok, got the shape. But how can I determine the object position in the next main loop iteration?
In case of 2 points (x1 != x2) I could use a linear function to calculate the intermediate positions, but it will not work for Z-shape where for one x we have multiple y's.
I guess I'm missing something very important here, there must be other solutions, please provide any hint so I can move forward...

[Edited by - teel on April 17, 2010 4:36:45 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!