How Do I Make Aliens move in waves?

BlitzMax Forums/BlitzMax Programming/How Do I Make Aliens move in waves?

Rico(Posted 2011) [#1]
I am making a shoot-em-up and i only know how to make objects move in circles using cos and sin, but i was wondering how to make aliens move in different patterns such as curves and snake-like waves? is there a tutorial on this somewhere? thank you


ImaginaryHuman(Posted 2011) [#2]
Sin() will give you a smooth curvy wave.

Otherwise you might want to consider some Artificial Intelligence like flocking or whatever. Or draw movement patterns with the mouse and record the positions to an array and then play it back to have the alien follow the positions.


Jesse(Posted 2011) [#3]
you can use spline's there are several examples in the code archives.
there is a tutorial on using splines in the shmupdev website that might be helpful for you:
http://www.shmup-dev.com/forum/index.php/topic,1638.msg16903.html#msg16903


Midimaster(Posted 2011) [#4]
To create a wave-like movement you only need one of the functions for the y-axis. The x increases linear:

For i=0 to 1280
       Plot i , sin(I)*30+200
Next


Last edited 2011


H&K(Posted 2011) [#5]
Record your mouse movements, smooth, play back as alien.
(Not claiming this is better way, just other way)

Last edited 2011


Yahfree(Posted 2011) [#6]
Look up parametric equations.. essentially, you can define a pattern with an x/y equation, then, using parametrics, find a point for a given third variable(that could represent a point in that animation). You would then just increment/deincrement this time variable every frame depending on which limit they reached last.


Kryzon(Posted 2011) [#7]
If you want choreographed movement you need some form of script where it will be registered.

You should delve into splines and other forms of curved functions, with which you can define sets of control points and literally draw the paths you want your objects to take.
This allows you to have the 't' time variable that Yahfree mentioned, that gives you the precise [X,Y] position an object should have while travelling through a certain path.
This 't' variable gives you complete control over how fast an object travels through a certain path, allowing you to implement slow-downs and speed-ups for your game.

---
This brings you two elements to program: the actual game engine framework that your characters will use to perform these scripted movements, and the tool you will use to build paths and preview multiple units orderly moving through them - just like they would in the final version.
Then have your game engine parse the script file this tool of yours should generate - which should contain path\curve definitions, enemy associations, points on the path where the enemies shoot or perform some action like opening wings, rotating, shooting, playing an animation, following another path etc. - and cache them to be played at the appropriate stage section (in case you have a scrolling stage, that is).

Last edited 2011


Rico(Posted 2011) [#8]
Thanks very much for all the help. I will look into splines and parametric equations as well. I really like Kryzon's idea of an editor where you can draw alien attack waves, and save them to a script file. I would like to make one of those eventually.

Thanks again :)


Taron(Posted 2011) [#9]
I would definitely do that through accumulative velocities, that's quick and easy and well to control.

For example it could go something like this:

local pos_x:float=300
local pos_y:float=0
local vel_x:float=-1.0
local vel_y:float=0.5
local target_x:float=50

pos_x:+vel_x
pos_y:+vel_y
if pos_x<50 then target_x=450
if pos_x>450 then target_x=50
vel_x:+(target_x-pos_x)*0.001

...or something like that. You'll figure it out.


Rico(Posted 2011) [#10]
Thanks Taron, i will try that as well, see which works best. I'll be working on the alien waves very soon, im just finishing off something else in the game first.