0 Favourites

# How do I create basic AI?

• 5 posts
• Just simple enemies that wander in a single direction, and change their direction appropriately when they collide with a solid. I'm trying to make a simple bomberman clone, and surprisingly this has been the most challenging part to think of. Every attempt I have ever made, the enemy always ends up going through walls, and it's quite frustrating. I've been trying to substitute "on collision" with "is overlapping" combined with triggered once, as I've heard that 'on collision' can be cpu intensive.

pls help!

• create an instance var for enemies called AI (number-type)

When AI = 0 and every 2 secs,

-> Set AI to choose(1,2)

When AI = 1

-> Simulate enemy "Right"

-> Set enemy to walk animation

-> Set enemy Not Mirrored

When AI = 2

-> Simulate enemy "Left"

-> Set enemy to walk animation

-> Set enemy Mirrored

Enemy has a wall to right

-> Simulate enemy "Left"

-> Set enemy to walk animation

-> Set enemy Mirrored

Enemy has a wall to left

-> Simulate enemy "Right"

-> Set enemy to walk animation

-> Set enemy Not Mirrored

That's a basic AI. You can set AI = 3 for run right, 4 for run left, 5 for attack, 6 for hurt, etc. if you want more complex AI

For run and attack, I suggest using a var to store every tick the distance between you and every enemy so each enemy will calculate its own unique distance from you, then use that distance variable to determine when enemy will attack (for example X<50 when close range attack, x>150 when long range attack). Differentiate Run from Walk by the speed (adjust both max speed and vector x for both run and walk). Of course animations of Run and Walk should be different, or at least different in animation speed.

Oh I forgot, you have to use "For Each: Enemy" on every single event of AI to make each behave independently from other enemy instances.

I hope this gets you started on AI. Good luck.

• Your method seems to be based on 2D platformers, I probably should have specified it's a top down game

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

Construct 3 users don't see these ads
• Your method seems to be based on 2D platformers, I probably should have specified it's a top down game

Oh, my bad. I am not familiar with the bomberman game. But if it's a top down game, you can pin another object that is longer (horizontally wider than your enemy, means higher X). It should be set to invisible and will act as sensor. So when it overlaps with your wall, check which wall (left or right) and change direction accordingly.

Btw, even if your game is top down, you can still use the same logic I used in my earlier post. Use an instance var called AI and assign a var value if moving left and another if moving right. Change the var when sensor overlaps with wall.

Hope it helps.

• You probably should check out this tutorial I made on how to make a bomberman game.

There are patrolling enemies that should be exactly what you are looking for, and everything is adapted to what you seem to want.

• 5 posts