PDA

View Full Version : Space Shooter smooth enemy movements...


Bunkai
06-02-2006, 02:33 AM
I develop a space shooter game and I am thinking what is the best way of defining the paths of my enemies. I need to fill these conditions:

1, I want to define interesting freeform circular paths
2, I want to easily get the rotation information of the enemy at any point in the path
3, I would be glad if I can slow down and speed up the enemies
4, The path should be easily editable and changeable

The primary two questions I have are: should the enemy movement be based on pregenerated pixel posisions? This would result in huge amounts of data but it would be the fastest way. Or, should I implement some spline curve algorithm and compute it in realtime? This would take much more time and probably I woudl have difficulties controlling the speed of enemies.

Or.. is there any standard, popular, and reliable way of defining of enemy spaceship paths?

Any help will be appreciated. Thanks a lot and have a nice day.

jankoM
06-02-2006, 02:45 AM
You can find my thinking about this theme here -> http://forums.indiegamer.com/showthread.php?t=6997

edit: I was replying this to your other question "How to implement enemy triggers for Space Shooter?" http://forums.indiegamer.com/showthread.php?t=7351

Bunkai
06-02-2006, 03:13 AM
Hello,

I've just read your another post. thanks.. The idea with XML looks interesting. and seems that it could work.

With regards,

joe
06-02-2006, 03:42 AM
Matt wrote a nice, free spline editor in BlitzMax. Have a look at it here:

http://www.shmup-dev.com/forum/index.php?topic=26.0

jankoM
06-02-2006, 03:48 AM
PTK has spline support allready in ...and that are dead simple to use too ;) . I don't know this but I heard patrox menthion something like "spline editor" on shmup-dev forum (http://www.shmup-dev.com/forum/index.php?topic=232.0) ... you might ask him if you are using c++ (ptk).

Bunkai
06-02-2006, 05:58 AM
Joe and Janko,

thanks for that Splie Editor. It looks great. However, the splines are so desdnes that if calculated in real time, the increment sizes vary in their lenght - that means, that the speed of enemies probably would not be constant.

Is using splines probably the best and only way? Say, if we precompute spline path, and ajdust it to make spline steps of equal size, can this approach be successful, or is just manual precomputing of enemy path just obsolete?

Thanks again..

Jason Chong
06-04-2006, 12:34 AM
I precalculate all my spline paths and store them in an array. Works like a charm for me.

Bunkai
06-04-2006, 04:58 AM
Hi Jason,

for resolution 480x640 you would get huge arrays probably.

Indeed, what tool do you use to design the splines initially? Have you developed some kind of tool for this purpose?

Jason Chong
06-04-2006, 07:17 AM
Hi Jason,

for resolution 480x640 you would get huge arrays probably.

Indeed, what tool do you use to design the splines initially? Have you developed some kind of tool for this purpose?


I don't have a full set of tools that are user friendly at all, just quick and dirty ones and implemented fast cubic curves and also catmull-rom, using those primitives to generate an array of x/y pair of points. As for huge arrays, Hmmm, don't really see how that's a big problem since I don't generate very fine and close points, and step values are large enough that you probably wouldn't use more than 3kb of memory per table generated. Patterns are always fixed, but you can easily use the same table data and adjust the offsets for other sprites that needs to use the same points.

I also generate tables for sine curves which I then use for snake/dragon like sprites.

Bunkai
06-04-2006, 10:32 AM
MS Excell comes to my mind as probably a very useful tool for generating XY coordinates based on spline formula. And, there is Matt McFarland's tool - a Spline Editor - that could be used for this purpose as mentioned by Joe above in this thread ..

electronicStar
06-04-2006, 10:45 AM
I don't do precalculated paths for any of my enemies.
I just give them a bunch of rules and behaviors and the path is calculated at each iteration. I have no problems with verying speed, it's just a matter of coding the right algorythm for what you want.
My 'enemy' class has calculation routines , I just have to set the presets for each enemy and it will move on its own.
It works well, and it's easy to have complex curved paths using trigonometry, you can also set more complex behaviours with states, etc , so the enemy can react to the player and go back to its routine, etc...

Bunkai
06-04-2006, 11:41 AM
Hello Electronic,

Would it be possible to explain deeply the logic of your algorithm? Are the paht splines randomly generated for your enemies? Or you define knot points, and the rest is calculated? What kind of splines do you use? And a spline is generated, there is index from 0 to 1 representing two spline ends. However, if you constantly move from 0 to 1, the spline step size varies, so it is difficult to keep contstant speed of your enemies. How do you solve this? Hopefully, I was clear enough,

With regards,

electronicStar
06-04-2006, 02:48 PM
I don't use splines per se, but combinations of curves (simple trigonometry) with constant speed factor, I can't really go in to more details.