1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GMS 2 made a basic code to get enemy to follow player and this happened

Discussion in 'Programming' started by no1youngin, Dec 2, 2019.

  1. no1youngin

    no1youngin Member

    Joined:
    Nov 28, 2019
    Posts:
    7
    .gif of the bug occuring here:
    https://gyazo.com/b8ee699a4b0dca579f87e359f6406e10

    this is my code i wrote in the step event of the enemy:

    if (instance_exists(obj_player))
    {
    move_towards_point(obj_player.x, obj_player.y, speed_);
    }

    only other thing in the enemy object is speed_ = 5; in the create event, I didn't know where to start seeking for help cause the code is so small. Please help!
     
  2. TsukaYuriko

    TsukaYuriko Q&A Spawn Camper Forum Staff Moderator

    Joined:
    Apr 21, 2016
    Posts:
    1,767
    That is to be expected - you have nothing in your code that tells it to stop moving if it's close enough to the player... ;)
     
  3. Catastrophe

    Catastrophe Member

    Joined:
    Sep 22, 2019
    Posts:
    222
    ^ Or if the problem is that it doesn't go right up to the player, I'm assuming your sprite origins are incorrect. If that isn't the issue, we'll need to know more xD
     
  4. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,136
    Looks like the player's sprite origin is set WAAAAAAAAAAAAAY off to the left (or right, if the player faces right by default) in empty space, as though the sprite was created by someone that didn't read the manual on sprite creation. :p

    What bugs me though is when the player seems to turn around at the end of that animation... Oh well. Fix your origin, then check for bugs again.
     
  5. no1youngin

    no1youngin Member

    Joined:
    Nov 28, 2019
    Posts:
    7
    I have the origin in a certain spot to draw my gun on it, is there any way I can make the enemy follow me without screwing up the placement of the gun? thanks!
     
  6. Rob

    Rob Member

    Joined:
    Jul 12, 2016
    Posts:
    716
    I think you should keep it as a friendly-but-annoying bot that sometimes says whacky things
     
  7. robproctor83

    robproctor83 Member

    Joined:
    Sep 30, 2019
    Posts:
    117
    Couldn't you just use point_distance to figure out if your too far away and if so then follow? Should be as simple as wrapping the move function with an if like this:

    if(point_distance(obj_player.x, obj_player.y, x, y) > 10){
    move_towards_.....
    }
     
  8. no1youngin

    no1youngin Member

    Joined:
    Nov 28, 2019
    Posts:
    7
    did this code exactly with my move towards player between the brackets, also MADE SURE my player origin was middle centre and it still happens just a little differently https://gyazo.com/3274a828c9c262ab090b78ec629b7c37
     
  9. no1youngin

    no1youngin Member

    Joined:
    Nov 28, 2019
    Posts:
    7
    fixed it! it was the origin of the enemy
    you were almost right it was the origin of the enemy not the player, thankyou!
     

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