Enemy AI in Space! Help!

This forum is currently in read-only mode.
From the Asset Store
Spaces Ambience contains 102 Sounds: 53 track and 49 sounds
  • I'm trying to make a Space Wars type game using construct. And have run into a bit of wall with the ENEMY A.I.

    <img src="http://i232.photobucket.com/albums/ee215/JDoejoe/SW-Help.jpg">

    I'm trying to figure out how to move the enemy towards the player, have the enemy fire at the player, and have the enemy avoid bullets and the Black Hole at the center of the playfield. All of this with the same 2d top-down space type movement (think: Space Wars, Asteroids, etc.) as the player uses.

    I'm getting that things like the RTS behavior seems to make the enemy move like a tank would -- i.e. Stop and turn, then move forward again... This doesn't really work for the game, which is quite "float-ie" right now, with lots of drifting and left over momentum -- and absolutely no stopping. There is also the issue of the constant gravity "pull" coming from the black hole element... The enemy a.i. needs to take that into consideration as it moves about the playfield. Trying to avoid getting too close, and then switching to an "escape" strategy if is gets caught in the gravity field.

    So, I was hoping someone could point me in the right direction to figure this out -- because I'm stumped, and I don't want to go off in the wrong direction entirely.

    Should I be looking at RTS and trying to figure out how to implement it? (I realize it's incompatible with the Physics behavior.) Is there another a.i. routine I should check out (Python plug in perhaps)? Even just help on the movement side would be great. Right now the player moves with physics and custom movement behaviors, producing a really nice "feel" for the game... How would I mimic that with the enemy?

    Any help/suggestions at all would be great. I think I need just be pointed in the right direction.

  • The line of sight behavior works for this, but since this is a space scenario Distance(x1, y1, x2, y2) should suffice.

    Basically what you want to do is compare the difference of space between the player, or obstacles, then if the enemy is within that radius have it do whats appropriate.

    There's also a nice little expression for aiming as well.

    http://www.scirra.com/forum/viewtopic.php?f=16&t=1378

  • Hey man, I've toyed with this a bit myself - got a video of my efforts here: http://vimeo.com/16387177

    I have a .cap of this here also: http://dl.dropbox.com/u/3317708/SB.zip

    I'm no expert, it's all very sticky tape and cardboard.

  • Hey man, I've toyed with this a bit myself - got a video of my efforts here: http://vimeo.com/16387177

    I have a .cap of this here also: http://dl.dropbox.com/u/3317708/SB.zip

    I'm no expert, it's all very sticky tape and cardboard.

    Thanks so much for sharing your game cap. That really helped!

    Based on that and what Newt was saying, I think I should be looking at Turret Behavior (which, of course, never even occurred to me before!) Thanks!

  • Okay, so I got the turret behavior going. And it works great for the "hunt" and "shoot" a.i. -- but I need to do an "Escape Black Hole" a.i. and I'm not sure how.

    It might just be something simple.

    Like if ship gets within a certain range of the Black Hole, turn 45 degrees away from black hole and thrust. Unfortunately, I have no idea how to turn away from something with turret behavior (and things like "rotate towards" don't look right at all) -- is there a math thing I'm missing?

    Do I need to control the ship without turret behavior? I found a "Physics Turret" in another thread:

    http://www.scirra.com/forum/viewtopic.php?f=3&t=6611&start=10#p52361

    I in no way understand it -- but should I be looking at something like that?

    Any other thoughts for a.i. avoidance with physics behavior?

    Thanks!

  • Yeah the turret behavior was designed to either be attached to something that moves, or stationary, so basically all its good for is attacking.

    Quite honestly you'd be better off dropping physics, and using the custom movement behavior, and either using the line of sight behavior, or distance(), with you own attacking/ retreating events.

    For the black hole there's even a command that would work well for that "restrain distance from position" If you use a lerp on the distance to restrain, and set it to "distance lower".

    Course you would have to have to include a escape velocity condition in there.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Yeah the turret behavior was designed to either be attached to something that moves, or stationary, so basically all its good for is attacking.

    Quite honestly you'd be better off dropping physics, and using the custom movement behavior, and either using the line of sight behavior, or distance(), with you own attacking/ retreating events.

    For the black hole there's even a command that would work well for that "restrain distance from position" If you use a lerp on the distance to restrain, and set it to "distance lower".

    Course you would have to have to include a escape velocity condition in there.

    Just when I got it all dialed in with physics and turret behaviors!

    If I were to stick with physics, I was thinking that I might create several "escape points" and arrange them around the black hole. And then assign them the attribute "escape point." That way, if the ship strayed too far into the "black hole zone", I could tell it to aquire the nearest escape point, target that and add thrust.

    <img src="http://i232.photobucket.com/albums/ee215/JDoejoe/SW-Escape.jpg">

    Unfortunately, when I try to do this, either with the "follow first in range" or even the "always the nearest" properties it refuses to work. It will only target one of the "escape points" and always the same one. If I then delete that escape point. It'll pick another one and target only that. Regardless of which one is closer.

    I even tried dropping attributes in favor makeing the escape points out of families instead. Still the same response.

    I must be doing something wrong.

    Right now it is:

    If Ships Distance to Black Hole lower than 350 > Aquire target "escape point." Add thrust.

    If Ships Distance to Black Hole greater than 350 > Go back to hunt and shoot behaviors.

    I've tried clearing the targets first, then acquiring the "escape points." Nothing works.

    Should I be using the "add object to target" action instead? What's the difference between "add object to target" and "acquire target"? I've tried using both at the same time to no avail.

    I wanted to see if something like this could work before I scrapped all the physics stuff I'm doing (there is alot of stuff that right now requires the physics behavior.)

    Any thoughts appreciated. Thanks!

  • Well I got a version of this working. Had a lot of confusion with the turret behavior. I kept trying to switch targets while using the "follow first in range" parameter -- but it would always just lock on to the first created instance of an object, even if it wasn't actually the closest.

    I took "first in range" to mean find the closest, and lock on ignoring all others. But it appears to be, find the first created of a particular object and ignore all others regardless of distance.

    Switching to the "always nearest" targeting method -- and always clearing all targets before adding new target finally did the trick.

    I know have some basic, extremely dumb, but working a.i.!!!!!!!

    Thanks CrudeMik and Newt

  • CrudeMik

    can you post the .capx again?? thanks

  • CrudeMik

    can you post the .capx again?? thanks

    rafaelsorgato

    You have posted in a 7 year old thread for software that was retired a long time ago, Construct Classic. CC doesn't create .capx - it creates a .cap which is in no way at all compatible with Construct 2 or Construct 3.

    Was this your intention?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)