Enemy AI in Space! Help!

For questions about using Classic.

Post » Thu Dec 16, 2010 4:15 am

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.
B
4
S
1
G
2
Posts: 64
Reputation: 980

Post » Thu Dec 16, 2010 4:34 am

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]
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Thu Dec 16, 2010 7:34 am

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.
B
39
S
12
G
8
Posts: 580
Reputation: 7,108

Post » Thu Dec 16, 2010 10:36 am

[quote="CrudeMik":2agn554y]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.[/quote:2agn554y]


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!
B
4
S
1
G
2
Posts: 64
Reputation: 980

Post » Fri Dec 17, 2010 7:45 pm

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?

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

Thanks!
B
4
S
1
G
2
Posts: 64
Reputation: 980

Post » Fri Dec 17, 2010 11:49 pm

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.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Sat Dec 18, 2010 1:36 am

[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.

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!
B
4
S
1
G
2
Posts: 64
Reputation: 980

Post » Sat Dec 18, 2010 11:30 am

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
B
4
S
1
G
2
Posts: 64
Reputation: 980


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 7 guests