Legacy GM [SOLVED] how to let object follow other object without flicking

jobjorgos

Member
Hey,

I have a boss that chases the player and that went pretty good with the following script:
Code:
if gofollow == true{
      move_towards_point( obj_player.x, obj_player.y, 9 );
}
But the small problem now is that whenever the boss is straight at where the player is, it is gonna flick which look really stupid. It should be more smooth or just flick less around by standing more still.

I did some research and I found this could be a solution:
Code:
if gofollow == true{
     if abs(obj_player.x-x)<5
     {
          speed=0;
     }else{
          move_towards_point( obj_player.x, obj_player.y, 9 );
     }

     if abs(obj_player.y-y)<5
     {
          speed=0;
     }else{
          move_towards_point( obj_player.x, obj_player.y, 9 );
     }
}
This indeed solved the flicking problem, it just stands still whenever it is straight at the players position which is nice!

But now the problem is that whenever the boss is on the same Y height as the player, that the boss object stop following the player.
When the boss is on the same X width as the player, it just works and it keeps following/chasing the player.

Is there anyway I can improve this code to prevent this? Thanks!
 
Last edited:

jobjorgos

Member
Well kinda stupid but just now when I was writing this topic here on the forum I came with the solution myself. When I was posting this boss I was just realizing that I didn't had to use speed=0; but should have used this:

Code:
if gofollow == true{
     if (abs(obj_player.y-y)<5) and (abs(obj_player.y-y)<5){
          move_towards_point( obj_player.x, obj_player.y, 9 );
          }else{
               if abs(obj_player.x-x)<5
               {
                    move_towards_point( x, obj_player.y, 9 );
               }else{
                     if abs(obj_player.y-y)<5
                     {
                          move_towards_point( obj_player.x, y, 9 );
                     }else{
                          move_towards_point( obj_player.x, obj_player.y, 9 );  
                     }
               }
        }
}
This works perfectly now! Sorry for posting a bit too quick on the forums here, I should have concentrated better on the code.
 
Last edited:

NwX-JuMPeUR

Member
Hello I am French so sorry if the translation is not correct. I had worked on a 2D project with zombies that had to chase my player no matter where he was in the room. I do not know if it can help but I used three ways to make it bug-free: -First the free move towards the player if there was no obstacle between the player and the zombie. -2th simple object bypass, I used a line collision between my zombie and my player that only applied at a certain distance. -3rd if the player is too far, I used a patch and mp_grid_path and all work perfectly. It's three techniques apply depending on the obstacle that the zombie could meet.
 
Top