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

GML How can i change the sprite angle of the enemy when he's falling (<3)

I

IsraelKaveski

Guest
So, i making a game plataform and my enemies can walk on objects and fall.
However, I would like that while they were falling, change their angle (to be more realistic) and when it touches the ground again, stay with the same starting angle.

This is the code i was using:

//gravity system
if (place_free(x,y+spdfall)){
y+=spdfall;
spdfall+=grvt
if (spdfall > maxspdfall){
spdfall = maxspdfall
}
} else {
spdfall = 2;
while(place_free(x,y+1)){
y++;
}
}


//Movement System
if(dir == 1){
if(place_free(x+4,y))
{
x+=2;
}else{
dir=-1;
image_xscale = -1;
}
}

if(dir == -1){
if(place_free(x-4,y))
{
x-=2;
}else{
dir=1;
image_xscale = 1;
}}

Event Create:
dir = 1;
spd = 4;
spdjump = 8
grvt = 0.4;
spdfall = 2;
maxspdfall = 8;

jump = false
jumpheight = 128;
jumpframes = 0;
 

flyinian

Member
To hold you over until someone with more expertise comes by:

My first thought would be to implement a "draw_sprite_ext" and change the angle when falling and reset it when on the ground.

My second thought would be to make actual falling sprites and draw those when falling. I believe, doing it this way will help avoid ugly looking sprites when rotating.
 

kburkhart84

Firehammer Games
My second thought would be to make actual falling sprites and draw those when falling. I believe, doing it this way will help avoid ugly looking sprites when rotating.
If its me...I take this suggestion. Yes, you could simply do some ugly rotation, but a different sprite would look much better. In either case, you need to learn about states, and storing what is happening at the moment. You need something that tells your character if it is falling, standing, jumping, walking, running, etc... If you go with a simple change to image_angle(or use draw_sprite_ext()), you will need to access the "state" to know which sprite to draw. If you take the better option and change actual sprite animation(possibly by changing the sprite_index variable), you will still need to access that "state" to know what sprite animation should be showing at any given time. Some platformer tutorials will show you this concept.
 

TheouAegis

Member
Just because you're falling doesn't mean your angle is going to change. if you fall straight down, you can still easily maintained a straight vertical position. People typically fall at angles because their legs are providing a greater vector than their torso at the time of propelling themselves off the ground. And when you dive, your legs provide a greater upward vector perpendicular to the angle of the torso, causing rotation; the falling has nothing to do with it. If you are tilted backwards when you are falling, it's usually either because there is greater weight on your back due to a backpack or something, or you tried to compensate the horizontal speed and ended up tilting backwards before the vertical vector kicked in.

Just pointing that out.
 
I

IsraelKaveski

Guest
Just because you're falling doesn't mean your angle is going to change. if you fall straight down, you can still easily maintained a straight vertical position. People typically fall at angles because their legs are providing a greater vector than their torso at the time of propelling themselves off the ground. And when you dive, your legs provide a greater upward vector perpendicular to the angle of the torso, causing rotation; the falling has nothing to do with it. If you are tilted backwards when you are falling, it's usually either because there is greater weight on your back due to a backpack or something, or you tried to compensate the horizontal speed and ended up tilting backwards before the vertical vector kicked in.

Just pointing that out.
I liked the tip, but forgot to warn that the enemies are slimes, lol.
But thank you very much for the point
 
Top