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

Animation Repetition

T

Tanner021

Guest
Hey all,

So, I am stuck in a situation where my main character is supposed to be stunned after being hit while also performing an animation and being moved slightly (automatically). The problem I am coming accross is that when he reaches the end of his animation (he is supposed to switch back to normal) he gets looped back into the same animation over and over again until he gets knocked off the stage. After digging I found out that the most likely problem is the image_speed in the reaction = 0 events.... When I remove it my player stops his movement and stops his animation so that he is back in his standing position. I would really like to have control over the speed of the animation, without it I have a player that moves as fast as flash.


movement = moveright + moveleft;
move = movement * movespeed;

if (place_meeting(x, y, o_enemyswinghitbox))
{
if place_meeting(x, y+1, o_walls)
{
reaction = 1;
}
else
{
reaction = 0;
}
}

if reaction = 1
{
move = 0;
x += sign(x -o_enemy.x) * 1.2;
image_xscale = sign(o_enemy.x - x);
sprite_index = s_maingettinghit;
image_speed = .2;
if image_index = 5
{
reaction = 0
}
}

if reaction = 0
{
if move = 0
{
sprite_index = s_mainstanding;
}
if move != 0
{
image_xscale = sign(move);

image_speed = move/35;
sprite_index = s_mainrunning;
}
}


x += move;
 
A

Aura

Guest
Code:
if (reaction && image_index >= image_number - 1) {
   reaction = false;
}
Also make it so that the player is re-stunned after it has recovered from the last stun by doing so:

Code:
if (!reaction) {
    if (place_meeting(x, y, o_enemyswinghitbox)) {
      //...
   }
}
 

TheouAegis

Member
In order for image_index + 0.2/s to ever equal 5, you must first set the image_index itself when you change the sprite. You changed the sprite but you didn't reset the image_index, which was probably animated at the time, so the current image_index wasn't able to ever equal 5.
 
T

Tanner021

Guest
Code:
if (reaction && image_index >= image_number - 1) {
   reaction = false;
}
Also make it so that the player is re-stunned after it has recovered from the last stun by doing so:

Code:
if (!reaction) {
    if (place_meeting(x, y, o_enemyswinghitbox)) {
      //...
   }
}
Wow, thanks bruh it flippin worked. I understand the second code you shared with me, but for my own information can you explain the first code you shared?
 
A

Aura

Guest
See: image_number

The code basically checks if the current image index is equal to the image index of the last image in the sprite (or larger). That signifies that the animation has played completely, that is, it has ended.
 

TheouAegis

Member
Your image_index never equals 5.000000000. In fact your image_index will never even equal 5, but GM:S seems to truncate image_index reads, so as long as the image_index is actually close enough to 5, it'd read as 5. Since you never reset the image_index, it ended up being too far over 5.00000000 to read. You probably could avoid using that code if you go with what I said while you were typing.
 
T

Tanner021

Guest
Your image_index never equals 5.000000000. In fact your image_index will never even equal 5, but GM:S seems to truncate image_index reads, so as long as the image_index is actually close enough to 5, it'd read as 5. Since you never reset the image_index, it ended up being too far over 5.00000000 to read. You probably could avoid using that code if you go with what I said while you were typing.
I'm glad I came back to this. Although your earlier post didn't need to be applied *At the time* , it really helped me with another issue. Thanks bruh.
 
Top