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.

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.[url:dbdz9olc]http://www.scirra.com/forum/viewtopic.php?f=16&t=1378[/url:dbdz9olc]

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:[url:1gayjnps]http://www.scirra.com/forum/viewtopic.php?f=3&t=6611&start=10#p52361[/url:1gayjnps]

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

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.

[quote="newt":rz36gi4h]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.[/quote:rz36gi4h]

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.

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.

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.

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?

If your vision so exceeds your ability, then look to something closer.