• 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!

GM2 Enemy issue

U

Ukaygee

Guest
Hey!

So in my game, I have 4 floor objects, and they are all children of the oCollision object. This oCollision object is what the player collides with. The issue I'm having, is that I'm trying to get the enemies to walk along a collision object, but as soon as they see a ledge, a wall or a oMoveable block, I want them to flip around and go the other way.
This is the code I use to do this:
Code:
if (place_meeting(x+sign(hspeed),y,oCollision)) // Are they about to walk into a wall?
{
    hspeed = -hspeed;
}

if ((!place_meeting(x+32*sign(hspeed),y+32,oCollision)) && place_meeting(x,y+1,oCollision)) // Are they about to fall off a ledge?
{
    hspeed = -hspeed;
}

if (place_meeting(x+8*sign(hspeed),y+16,oMoveable)) // Are they about to walk on a half block?
{
    hspeed = -hspeed;
}
upload_2018-1-10_14-39-14.png

So as you can see here, the pink enemy will walk to the right, along these 32x32 blocks, but I want them to start walking left as soon as there is a half block right next to them. The code above works perfectly, but unfortunately I cannot set up a collision code for the player, otherwise my game gets a bit laggy, and I can't parent these half blocks to the oCollision object, otherwise the enemies would ignore the code telling them to not walk on the half blocks.

Does anyone have an efficient way to do this? Sorry if I made absolutely no sense :p
 
Top