1. Hey! Guest! The 33rd GMC Jam will take place between May 23rd, 12:00 UTC (Friday noon) and May 27th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Flying Enemy Charge AI

Discussion in 'Programming' started by JeanSwamp, May 15, 2019 at 11:33 AM.

  1. JeanSwamp

    JeanSwamp Member

    Joined:
    Jan 11, 2018
    Posts:
    106
    Hello,

    I'm trying to get some sort of flying enemy charge towards the player. I'm moving the enemy towards the player like this:

    Code:
        hsp = lengthdir_x(6,point_direction(x,y,_playerx,_playery))
        vsp = lengthdir_y(6,point_direction(x,y,_playerx,_playery))
    Now, what's a good way to stop this on a timer, or when reaching certain point to make the enemy leave this charge state smoothly.

    The idea is to allow the player to be able to dodge the charge by moving, since the enemy will charge towards the current player location in the moment the charge began.

    Thanks
     
    Last edited: May 15, 2019 at 11:39 AM
  2. johnwo

    johnwo Member

    Joined:
    Jun 20, 2016
    Posts:
    199
    At charge start, set playerx/y then just go towards that x/y...

    Edit: You changed the question.
    Using alarms/point_distance to stop the charge would be the easiest way to go about it.
     
  3. JeanSwamp

    JeanSwamp Member

    Joined:
    Jan 11, 2018
    Posts:
    106
    Problem is I just don't want to stop it based on an alarm, because it won't take in consideration from how far the charge began, so if it was further away, it might not even reach the player.

    This is more or less what I'm doing. Is working but I need it to be a bit more smooth and random.

    Code:
    #region Warning
    if e_state = e_states.warning
    {  
        sprite_index = sEnemy1_Attack;
        hsp = 0;
        image_speed = 0;
    
        // THROW ATTACK WHEN THE WARNING IS OVER
        if attackwarning == 0
        {
                image_index = 0;
                e_state = e_states.attack
                startx = x
                starty = y
                targetx = oPlayer.x
                targety = oPlayer.y
        }
    }
    #endregion
    
    #region Attack
    if e_state = e_states.attack
    {
        hsp = lengthdir_x(6,point_direction(x,y,targetx,targety));
        vsp = lengthdir_y(6,point_direction(x,y,targetx,targety));
       
        if point_distance(x, y, targetx, targety)  < 8
        or place_meeting(x+hsp,y,oPlayer)
        {
            attackcd = 150;
            e_state = e_states.recovery;
        }
    }
    #endregion
    #region Recovery
    if e_state = e_states.recovery
    {
        misctimer++
        if misctimer >= 20
        {
            hsp = 0;
            vsp = 0;
            misctimer = 0;
            e_state = e_states.stepback;
        }
    }
    #endregion
    #region Step Back
    if e_state = e_states.stepback
    {
        hsp = lengthdir_x(2,point_direction(x,y,startx,starty));
        vsp = lengthdir_y(2,point_direction(x,y,startx,starty));
        if point_distance(x, y, startx, starty)  < 8
        {
            hsp = 0;
            vsp = 0;
            e_state = e_states.run;
        }
    }
    #endregion
    I want both the attack reaching it's end to be a bit smoother and fluid, and same for the step back, currently I'm moving it towards the starting pos but I would like to reposition in another different stop to add randomness.
     
    Last edited: May 15, 2019 at 12:06 PM
  4. johnwo

    johnwo Member

    Joined:
    Jun 20, 2016
    Posts:
    199
    What do you mean by "smoother"? Smoother in terms of timing, or smoother as in terms of motion? If it's in terms of motion, do you want the speed to ramp up or down? Do you have any examples/references?
    The question is just a bit ambiguous...
     

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