Enemy Tank AI

For questions about using Classic.

Post » Tue Feb 23, 2010 1:38 pm

Why hello there, I was working with MMF2 and now I changed to Construct, because it's more powerful and you can do better things.

Now onto my problem. I'm trying to make a game. Now I have a big problem with the enemy. I wanted that the Enemy Tank just walks randomly somewhere and he turns himself, when he doesn't see the player. After seeing the player (with a range), he should follow him, but still have a path. Not that he runs into a wall and just stays there.

With the range, I just made this with a sprite that should be invisible (but isn't for testing purpose). First he goes somewhere and overlaps a wall, he turns slow. So he goes through the wall and back again. Then when he gets stuck on a corner, he just turns round like crazy and randomly comes out of the corner. If he follows the player, he gets stuck on the wall or jitters randomly on the wall.

Any help here? :D

[Edit: Hmm, can't attach here... Then, here is the CAP File of my game if it's needed.
B
7
S
1
G
2
Posts: 87
Reputation: 1,099

Post » Tue Feb 23, 2010 2:06 pm

Two things I can say - you sure you want the tank to move at all angles? If it was limited like the player to basically 90 degree increments it would be easier to make a simple movement solution (Hit wall - turn 90 degrees - hit again - turn -90 degrees, hit again - turn 90 degrees, etc And each 5 or so iterations turn 90, 90 just so it doesn't get stuck too much). Then it could have a simple automated patrol route and just set the direction to closest 90 degrees to the player.

Well, something like that. It'd also be oldschool :)

Also - there's a nice command for distance between two points in Construct so you don't need the big white sprite as a detector.

I really like how everything's nicely separated into Event Sheets, though.
B
19
S
6
G
6
Posts: 1,101
Reputation: 5,646

Post » Tue Feb 23, 2010 2:44 pm

Hmm, not bad Idea. Now I added a Hitbox for the tank and changed the Movement and everything to the Hitbox. Also there is a new Spawning Object. Now a dumb thing is, if it spawns, the tank always spawns diagonally, breaking the purpose of the hitbox. Did I do something wrong?

Here a new version of the cap, showing all the hitbox, spawn objects and other stuff.
B
7
S
1
G
2
Posts: 87
Reputation: 1,099

Post » Tue Feb 23, 2010 3:39 pm

Hey, I just wanted to realize the simple idea I mentioned above so quickly threw this together: [url:3aq9qfdo]http://dl.dropbox.com/u/1328856/SmallTank.cap[/url:3aq9qfdo]

It's really pretty crap, but at least that little tank doesn't run straight through the walls and makes it look like he's navigating... something. Heh.

Anyhow - a system like this would need to use the Object Pairer to link the tank and his navigation sensors, but that's not too tough and there are examples here on the forum.

Like was said - pretty crap - but maybe good for some ideas.
B
19
S
6
G
6
Posts: 1,101
Reputation: 5,646

Post » Tue Feb 23, 2010 4:55 pm

This isn't crap! This is the thing what I need! I like the fact that he's randomly going. The only thing to do is, that he isn't always at the wall but also going on the middle of the level and so.

And now, I miss the Randomize Object from MMF2, any idea how to make it, so that after random milliseconds, the tank turns?
B
7
S
1
G
2
Posts: 87
Reputation: 1,099

Post » Tue Feb 23, 2010 6:28 pm

there's a random expression in the system object.

random(x) will return an integer between 0 and x-1 (inclusive)
such that random(4)*360 yields either 0, 90, 180 or 270 ;)
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Tue Feb 23, 2010 6:42 pm

Yup, was about to say that - here's an example where the tank gets the need to turn every now and then: [url:3rovlaf6]http://dl.dropbox.com/u/1328856/SmallTank.cap[/url:3rovlaf6]

But it's done with the system timer - you'd have to give each tank a timer behavior and do checks with that (gotta read up on it) - otherwise all the tanks would turn at the same time.
B
19
S
6
G
6
Posts: 1,101
Reputation: 5,646

Post » Tue Feb 23, 2010 8:19 pm

Thank you, this should finally fix my problem that I was thinkering for a week :lol:

Just to ask, Somebody. Are those Tank graphics you used for the examples, are they used in any games? I want to use them. :mrgreen:
B
7
S
1
G
2
Posts: 87
Reputation: 1,099

Post » Tue Feb 23, 2010 8:31 pm

I just drew them for the examples, use them if you want to, sure.

If I make a little tank game it'd be a slightly different style, so no problem there. But there's one thing I have to reserve - the title Pank Tanic! :lol:

No, seriously, use whatever you like. And equally seriously - Pank Tanic is from now on reserved as a tank game name. :D
B
19
S
6
G
6
Posts: 1,101
Reputation: 5,646

Post » Tue Feb 23, 2010 8:49 pm

Ok xD
Will you give me a lawsuit if my game is called "Tank Panic"? :P

Also, is it only in 0.99.82 that Construct crashes when I copy a object from one cap to another cap?
B
7
S
1
G
2
Posts: 87
Reputation: 1,099

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests