Jump to content
  • Advertisement
Sign in to follow this  
deepie

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

This topic is 4954 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!