How do I program simple AI?

0 favourites
  • 13 posts
From the Asset Store
Basic Rounded Vector Geometry Player Design with Glow for 3 player games
  • 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.

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

  • Do you have a exemple? i tried make but don't work

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

  • mestrejedi3221 find your answer here

    https://www.dropbox.com/home/Demos

  • Lordshiva1948 , your link is no good, and I don't see any AI in your dropbox portfolio.

  • 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

  • mestrejedi3221 find your answer here

    You send the wrong link

  • 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

  • mestrejedi3221 sorry here is AI.capx

    https://www.dropbox.com/s/6f9pp904pq2jl0s/AI.capx?dl=0

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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

    Thanks man this work

  • mestrejedi3221 sorry here is AI.capx

    Thanks for the system.

    With small changes, this is perfect to my game.

  • You're welcome, nice to help

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