Tracking 2D objects on a path / pre-determined movement

I guys
i have crated a side scrolling space shooter game.

the enemy of my games has all a very basic movement (left to right, go directly to the player etc…), and before to start to reinvent the wheel, i would like to know whot are good stategies to create more complicated object movement.

I’d like to have enemy them perform more movements such as moving down the screen, go to left go up again etc…
I belive that I have to create a Path and iterate on it during the update logic of the enemy Sprite.

My question is if someone of you know same resource that i can use to study at list the basic of the path creation and iteration
or if you can share with me your strategy to give me some idea, or you know if there are already some implementation that i could use to do it
thanks

You probably want to define your paths as splines, and move your enemies along them at a fixed rate. Pick something from here and implement it is a good starting point: http://en.wikipedia.org/wiki/Category:Splines

Bezier curves are a nice simple one to start with: http://en.wikipedia.org/wiki/Bézier_curve

But you may want to progress to something more complicated depending on what your movement should look like.

Splines are very useful, indeed. If you want to do more research, check he general idea of “parametric curves”.

Generally they work like (x,y) = f§, and give you the position on the curve for p in [0…1] (or any other interval, but usually normalized). If you modulate the step size of p, you can speed up/ slow down your object while they follow the curve. You can also have sequences of curves that the objects will follow, but if you use splines you can make one spline with all twists and turns.

There are also examples for 3D curves and parametric surfaces there.

Edit: If you find a way to make splines from random parameter sets, you’ll have a shooter where even you as creator can’t predict the enemies, and it will be a constant challenge even for yourself ;D

thanks guys for your suggestion! :slight_smile:

I create my implementation that i shared with the guys that will need it
this is the link :point:

In my game i use Cubic Hermite splines. I also need to move along the curve at constant “speed” ie t needs to be parametrized in terms of cord length. I found that using a 2nd order Gaussian quadrature was more than accurate enough just to create approximate “look up table” of distance vers t. All my unit movement uses this rather than “true physics”. Yet it gives the illusion of being a full physics model, while permitting easy “move here via there” control.

hi delt0r

your solution look like very interessing…

actually my implementation suffers exactly of an indeterminant speed long the segment of the bspline created.

can I see some snippets of code or discuss with you about the implementation of this solution?
i would try to add also this algorithm to my implementation and sahre to all the guys in the forum.

Currently the code is not very tidy. But i sure don’t mind sharing. I will try to do so by the end of the day.
[edit] Also i am on irc #lwjgl.