Public Group

# How to store the path the object should follow?

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

## 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 on other sites
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 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.

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]

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 11
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633722
• Total Posts
3013540
×