Artificial intelligence

Get help using Construct 2

Post » Wed May 23, 2012 6:31 pm

So, I need some help creating AI for my game. I'm going to include my .capx so its not so confusing. Basically, I need the enemies (which are brown tanks) to rotate towards the player(Big green tank) and then shoot at the player. I got the shooting part figured out, but the rotating is not working. I've already tried an attempt at this, but its not working so good. The problem I faced with it was that I couldn't implement it to other enemies in the game. Also, the way the sprites are drawn are throwing me off.

So if anyone can figure out how to make this and be able to transfer easly to other enemies, I would be happy     

P.S I'm using the battlefield art pack that is included when you buy construct 2 standard license.

The project
Posts: 41
Reputation: 1,548

Post » Wed May 23, 2012 10:53 pm

1\ System condition doesn't pick (unless it's a foreach, a pick nth instance, or a pick random instance)
2\ You use a global variable to carry the direction, thus applying the same value for everyone

Things could be waaaaaay simplier:[code]+Enemy: Is on-screen
-> Enemy: set a to ceil(((angle(self.x,self.y,player.x,player.y)+360)/45)-0.5)%8
-> Enemy: set animation to "direction_"&a
+System: Every 3 seconds
+System: For each Enemy
    -> Enemy: Spawn Ts on layer 4 at image point "shoot1"
    -> Ts: set bullet angle to Enemy.a*45 degrees
    -> Audio: Play Explosion1 no looping (tag:"")[/code]
These few line should replace your "AI_AimAtAngles" and "AI_ShootWhileonScreen" groups
Note that you'll have to create an instance variable named 'a' type number for your enemies
And also rename your animations:
- right -> direction_0
- rightdown45 -> direction_1
- down -> direction_2
- .. etc (respect the clockwise rotation)
Posts: 1,479
Reputation: 16,336

Post » Thu May 24, 2012 4:10 am

Wow! thank you so much! Exactly what I needed I knew there had to be a simpler way of doing the aiming
Posts: 41
Reputation: 1,548

Return to How do I....?

Who is online

Users browsing this forum: iceangel, Voni, Yahoo [Bot] and 20 guests