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

Jumping Enemies

Hello GMC! I've been curious for a while about how to make a jumping enemy ai in a sidescrolling game. Haven't found any tutorials on it yet. I'm thinking of anything from a dog, spider or even a knight that will leap at the player to attack. I'm certainly aware of states and whatnot, I just need to figure out how one would do this? Here's the gravity/collision codes for my current game:

collisions:

Code:
///move
// Horizontal collisions
if (place_meeting(x+hspd, y, SolidParent)) {
    while (!place_meeting(x+sign(hspd), y, SolidParent)) {
        x+=sign(hspd);
    }
    hspd = 0;
}
x+=hspd;

// Vertical collisions
if (place_meeting(x, y+vspd, SolidParent)) {
    while (!place_meeting(x, y+sign(vspd), SolidParent)) {
        y+=sign(vspd);
    }
    vspd = 0;
}
y+=vspd;
gravity:

Code:
///apply_gravity
if (!place_meeting(x, y+1, SolidParent)) {
    vspd += grav;
}
Any help for figuring how exactly to go about this would be awesome! :)
 

obscene

Member
Many ways to do it. Perhaps if your enemy is trying to move towards the player but the x is not changing (stuck against a wall) the tell it to jump.
 
Top