scripting enemy movements - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: scripting enemy movements (/thread-9359.html)
scripting enemy movements - anthony - Sep 25, 2011 11:32 AM
I'm working on a space shooter (galaxian / space invaders style) and I'm a bit stuck on the enemy movements.
See how the enemies move in this video: Demon Attack
I'm guessing these are scripted / hardcoded movement patterns. I've been trying to do something similar with an array of (x,y) coordinates that the enemies iterate through during their life time. Each element in the array is a pair of values to add to the x and y coordinates of the enemy.
It doesn't look that great (quite jittery) and I end up with a huge array of coordinates which feels inefficient.
I've also tried using sine and cosine wave based movements - which doesn't look too bad but doesn't give the variety of movement I'm after.
I'd be really grateful for some advice / tips / links!
RE: scripting enemy movements - OneSadCookie - Sep 25, 2011 12:33 PM
IDK how it's traditionally done, but I'd probably use bezier curves for something like galaga. They're straightforward to code and easy to create/edit, even adjusting the coords by hand if you don't have time to hook up a graphical editor.
RE: scripting enemy movements - vzykov - Sep 25, 2011 11:23 PM
Looks like there are at least three components to the enemy movements in the video. First, an overall downward movement, towards the player. Second, a rough circling motion. And third, some responsiveness to the player's x position.
One way to model that could be to add together:
a y component that is gradually increasing,
a sin-based component, that creates a circular motion (maybe an oval with a rotating axis), sometimes randomly reversing to keep things interesting,
and an x component that will increment a fixed amount to the left or right every second or so, based on whether the player is to the left or to the right of the enemy.
...that might be an oversimplified description of the motion though. Try watching the slow-motion part many times and seeing if you can make an exact description of the movements. If you can describe it, you can model it!
RE: scripting enemy movements - anthony - Sep 26, 2011 11:08 AM
Cheers for the replies guys!
And then in my alien's update function, I have a switch statement that moves the alien in the direction of the current move.
It's not high tech but it's working well. I find I have more control over the movements and have been able to create 3 distinctive movement patterns quite easily.
It also means that I can add an action to the MovementData(), for example a "shoot" action, fairly easily.