Advertisement

Best way to model AI for a 2d shoot em up?

Started by May 23, 2005 01:47 PM
5 comments, last by Kylotan 19 years, 6 months ago
Hi there, Im currently working on a top down 2d shooter. Rather than simply have the enemy ships move in a straight line from the top of the screen to the bottom, I wish for the enemy ships to follow a predetermined path. For example, I would want one of the ships to move from the top of the screen downwards, move in a loop before continuing down the screen. The only problem is that im not sure how I should model this so ships can follow a predetermined path? I appreciate any help anyone can offer. TIA deepie
I'm attempting something similar by scripting enemy movement with curves. Bezier curves are reasonably simple to create, but moving an enemy along it's path can be a bit of a pain. If you want something simpler you could just define a bunch of waypoints and move from one to another. Add some simple asteroids-style physics and that should smooth out the corners somewhat.

I'm also playing with the idea of a metaball-esque energy field (think negative waypoints which ships avoid). Could be nice with some added flocking, but I havn't tried this yet...
Advertisement
Perhaps instead of following paths, they would follow a series of commands that would place them on that path.

The commands would be in 2 parts, the instruction, and the time since creation of enemy in which the command is to be executed.

example:
time/command
2/begin moving sttraight at speed 3 in down direction
3.5/continuous right turn(as in it won't stop turning until it recieves a new command)
5/move straight


Anyway you get the idea.
EAX
Probably what your looking for are points.

Basically, you set up a group of points.

Your ship is attracted to points in front of it, and less so to those behind it. (this includes a turning motion, so it will point towards the point).

Occasionally you can get some... Odd things. (like a ship going into orbit.), but most of the time it'll do what you want.

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
I think I am going to try follow a waypoint type system.

I currently make the ships move by defining a direction vector for them and moving them in that direction. I reckon by following a series of waypoints, I would be able to make the ship change direction once it gets within a certain distance of a waypoint by recalibrating the direction vector so that it points to the next waypoint.

If I can define several arrays with a series of different waypoints then essentially I would have a collection of different paths. Then I would just have to associate an array with an enemy ship which then follows that series of waypoints.

My only concern is that the fewer waypoints I have, the more jerky the motion of the ship will be as it changes direction. Is there a way around this rather than simply defining more waypoints?

Thanks for your help guys :)
Try the system as i outlined it.

ALL waypoints influence the direction, tho ones closer to it influence it more.

This stops jerkyness.

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
Advertisement
Quote: Original post by deepie
My only concern is that the fewer waypoints I have, the more jerky the motion of the ship will be as it changes direction. Is there a way around this rather than simply defining more waypoints?


Yeah, that's what the mention of bezier curves above was about. Alternatively if your waypoints are all in a line (ie. no circular or backwards paths) you could use cubic interpolation to round off the paths.

This topic is closed to new replies.

Advertisement