How do I program simple AI?

Get help using Construct 2

Post » Sun Sep 20, 2015 3:13 am

Hello everybody!

I need some help regarding the proper programing of an AI, for a simple 2D side-scroller shooter game.
The AI objects are supposed to be enemy soldiers. The AI will only need to shoot and move horizontally, as well as, follow the player until it comes out of the AI aggression range.

Please if anyone is able and willing to help, comment in this thread.
B
9
S
1
Posts: 7
Reputation: 429

Post » Sun Sep 20, 2015 9:00 am

For simple AI you could use a distance check

system compare two values : distance(player.x,player.y,enemy.x,enemy.y) < your desired amount

Then you could check if the enemy is in the left or right of the player and have it move/shoot accordingly..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sun Sep 20, 2015 10:01 pm

Do you have a exemple? i tried make but don't work
B
9
S
1
Posts: 7
Reputation: 429

Post » Mon Sep 21, 2015 11:29 am

If you could share your capx and/or a screenshot of your event sheet I'd be glad to explain why it isn't working..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775


Post » Mon Sep 21, 2015 6:09 pm

@Lordshiva1948 , your link is no good, and I don't see any AI in your dropbox portfolio.
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,414
Reputation: 4,822

Post » Tue Sep 22, 2015 11:43 pm

LittleStain wrote:If you could share your capx and/or a screenshot of your event sheet I'd be glad to explain why it isn't working..


This is my frustrated try

Image
B
9
S
1
Posts: 7
Reputation: 429

Post » Tue Sep 22, 2015 11:45 pm

Message: mestrejedi3221 is not yet permitted to post plain text URLS (300 rep required). 1 URLS removed. Why?
Lordshiva1948 wrote:mestrejedi3221 find your answer here


You send the wrong link
B
9
S
1
Posts: 7
Reputation: 429

Post » Wed Sep 23, 2015 2:58 am

Hi mestrejedi3221.

First I would include the platform behavior to enemies (or 8 directions if it is no platformer), it will be much easier to control their movements this way (don't forget to put "Default controls" off).
Also use an instance variable in enemies to memorize the player even if he left the LOS, being able to run after him then. Let's call it "Memory" (initial value = 0)

About shooting I would do something like :
("-" represents sub event)

if Enemy has LOS to player : Set memory = 1
-Enemy compare X : if greater than Player. X : Set mirrored
-Enemy compare X : if lessthan Player. X : Set not mirrored
-Every 3 seconds : Spawn bullet

About moving to the hero :

if Enemy has NOT LOS to player :
and Enemy memory = 1
-Enemy compare X : if greater than Player. X : Simulate control Left
-Enemy compare X : if less than Player. X : Simulate control Right

Does it help ?

Vega
B
21
S
4
Posts: 40
Reputation: 1,107


Next

Return to How do I....?

Who is online

Users browsing this forum: megatronx, RetrocadeMedia and 1 guest