• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Platformer Enemies Spazz out on top of Player [SOLVED!]

R

Reyniki

Guest
[EDIT] My previous concern was solved but now I'm kinda lost on how to make the enemy sprites stop spazzing out when they're overlapping with the player.

Dunno if any line of code would show the problem but here's the enemy's chase after the player code:

Code:
dir = sign(oPlayer.x - x);
h_sp = dir * 2;

//Player no longer in range
if (!collision_rectangle(x+aggro, y, x-aggro, y-128, oPlayer, false, false)) {
    state = ENEMYSTATE.FREE;
}

//Attack
if (collision_rectangle(x-aggro/6, y, x-aggro/6, y-128, oPlayer, false, false)) {
    state = ENEMYSTATE.ATTACK;
}

sprite_index = sRagnar_RunningR;
image_xscale = sign(h_sp);
 
Last edited by a moderator:

TheouAegis

Member
if h_sp != 0 image_xscale = sign(h_hsp);

That will prevent the sprite from blinking away.

For actual movement, I prefer to put the enemy on a timer before letting it change directions.

if global.step_counter mod 8 == 0 {
dir = sign(oPlayer.x - x);​
 

Simon Gust

Member
I prefer to put a radius around the player, that the enemy has to walk outside before turning inwards again.
Code:
if (x < oPlayer.x - aggro / 3) dir =  1;
else
if (x > oPlayer.x + aggro / 3) dir = -1;
 

Nidoking

Member
When you get to within h_sp of the player, you'll need to adjust the movement so the monster goes directly to the player's location instead of continuing to move at full speed.
 
R

Reyniki

Guest
Hey guys, thanks for the input! I tried all of these ideas to the best of my ability but I realized that if I just used "place_meeting" with the player's x and y, and switch the state to the attack state, it pretty much solves the problem :D
Now to figure out how to make the sprite stop doing the spazzing thing all over again when the player's below or on top of them (like pixels below/on top, not overlapping)
 
Top