Enemy Tank AI

This forum is currently in read-only mode.
0 favourites
From the Asset Store
Give Sound to the enemies that are part of your game! :)
  • 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?

    [Edit: Hmm, can't attach here...

    Then, here is the CAP File of my game if it's needed.

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

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

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

    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.

  • 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?

  • 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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yup, was about to say that - here's an example where the tank gets the need to turn every now and then: http://dl.dropbox.com/u/1328856/SmallTank.cap

    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.

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

    Just to ask, Somebody. Are those Tank graphics you used for the examples, are they used in any games? I want to use them.

  • 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!

    No, seriously, use whatever you like. And equally seriously - Pank Tanic is from now on reserved as a tank game name.

  • Ok xD

    Will you give me a lawsuit if my game is called "Tank Panic"?

    Also, is it only in 0.99.82 that Construct crashes when I copy a object from one cap to another cap?

  • Will you give me a lawsuit if my game is called "Tank Panic"?

    Of course not, that's NOTHING like Pank Tanic?

    Also - not sure about the copying thing, but here's a tank base and a top for more testing:

    <img src="http://i244.photobucket.com/albums/gg36/some9000/TT1.png">

    <img src="http://i244.photobucket.com/albums/gg36/some9000/TT2.png">

  • No, no. Graphics work fine.

    But if I mark a object, like the Collission Arrow from your Example project, CTRL+C. Now I go to my project and press CTRL+V, then I get the plus sign (where to put the copied file). Then it gets stuck and at the end, it says the app crashed. Or once it crashed with another message.

    Try to copy a object from one cap to another cap and see if it crashes to you too...

    Anyway, I just made new sprites and added all the graphics and everything. Now it works perfectly. Now onto making the real game

  • I hope my Double Post doesn't kill someone

    Anyway, yay for another problem. I found out how to make the distance without the big circle I previously made. Now, I want the enemy to follow the player, but with the limits to up, down, left, right and not in 360?.

    I tried with "random(4)*360" which wasn't really a good idea

    And also used some other commands to make this happen.

    Yeah! "tanks.cap" Link

    As always, I really appreciate any help

  • Neo1000,

    To stop the crashing, make sure you have both .cap files open in a SINGLE instance of Construct. If you have two "Contruct" apps in your taskbar, it will crash.

    When you have them both open in a single instance, you can change between .cap files via the Project tab.

  • Ah, that makes sense. But with more instances, Windows 7 will show more projects on Aero Peek.

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