GML Enemy AI - UP AND DOWN

Discussion in 'Programming' started by shoyguer, Jun 2, 2018.

  1. shoyguer

    shoyguer Member

    Joined:
    Jun 2, 2018
    Posts:
    2
    Hello, for hours I'm trying to programming the AI of the enemies of my game but I have a throuble....
    I just want to do the ghosts (enemies) fly up and after some seconds fly down, and do an infinite loop.
    Here's my code:


    Create:

    ydirection = 1;
    yspeed = 0.35;

    loop = 0;


    --------------------------


    Step:

    if (loop <= 10) {
    alarm[1] = 120;
    loop = loop + 1;
    }

    y = y + (yspeed * ydirection);

    ---------------------

    Alarm[1]:

    ydirection = ydirection * -1;

    ---------------------------------------------------


    Thank you all !!!!
     
  2. Dupletor

    Dupletor Member

    Joined:
    Apr 22, 2017
    Posts:
    328
    shoyguer likes this.
  3. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,889
    if abs(y-ystart) >= amplitude ydirection = -ydirection;
     
    shoyguer likes this.
  4. Jdown79

    Jdown79 Member

    Joined:
    Aug 21, 2016
    Posts:
    69
    Or even simpler, for an object this basic, use inbuilt paths
     
  5. shoyguer

    shoyguer Member

    Joined:
    Jun 2, 2018
    Posts:
    2
    Thank you very much!!!!!!!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice