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

Attack and jump animation not working

C

Cheinberger

Guest
Hello!
I am fairly new to GM and have been watching tutorials on a side scroller. I have made my own sprites and animations, but when I put the code in, no matter what I do, when I press the left mouse button (attack button), my character plays the 1st frame of the animation, and immediately goes back to the idle animation at lightning speed. It is hard to tell he is even attacking. My running animation, moving while crouching animation, and idle animations all work just fine, but when it comes to attacking, no dice. Same with jumping. My character is stuck on one frame while jumping, and if I try to change the image speed, he moves vertically, but the animation will not play. Please help! I am not an experienced coder. Thank you!
P.S.
My jumping animation is 27 frames and my attacking animation is 5.

Here is everything I have code wise in my Player object. I understand it may not be organized lol.

key:
hsp = horizontal speed
vsp = vertical speed
oWall = invisible borders such as the ground or an actual wall


//Get Player Input
key_left = keyboard_check(ord("A"));
key_right = keyboard_check(ord("D"));
key_jump = keyboard_check_pressed(vk_space);
key_down = keyboard_check(ord("S"));
key_up = keyboard_check(ord("W")) or keyboard_check(vk_lshift);
key_attack = mouse_check_button_pressed(mb_left);

//Calculate Movement
var move = key_right - key_left;

hsp = move * walksp;

if (key_down = true)
{
hsp = move * crouchspeed;
}
if (key_up = true) && (key_right or key_left= true) && (key_down = false)
{
hsp = move * sprintspeed;
}
vsp = vsp + grv;

if (place_meeting(x,y+1,oWall)) && (key_jump) && (!key_down)
{
vsp = -1.7;
}
if (place_meeting(x,y+1,oWall)) && (key_jump) && (key_up) && (!key_down)
{
vsp = -2.5
}
//Horizontal Collision
if (place_meeting(x+hsp,y,oWall))
{
while (!place_meeting(x+sign(hsp),y,oWall))
{
x = x + sign(hsp);
}
hsp = 0;
}
x = x + hsp;

//Vertical Collision
if (place_meeting(x,y+vsp,oWall))
{
while (!place_meeting(x,y+sign(vsp),oWall))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;

//Animation
if (!place_meeting(x,y+1,oWall))
{
sprite_index = CharacterFallfrontR1
image_speed = 0;
if (sign(vsp) > 0) image_index = 1; else image_index = 0;
}
else
{
image_speed = 1;
if (hsp == 0)
{
sprite_index = CharacterStandingR;
}
else
{
sprite_index = CharacterRight;
}
}
if (key_down = true)
{
sprite_index = CharacterCrouch
}
if (key_down = true) && (hsp!=0)
{
sprite_index = CharacterCrouchMove
}
if (key_attack)
{
sprite_index = CharacterAttackR
image_speed = .1
}
if (hsp != 0) image_xscale = sign(hsp)/2;
 
Last edited by a moderator:

hogwater

Member
Please use the [code*] [/code*] tags (remove the asterisk) for posting code, it makes it much easier to read. No green text either.

You will be much more likely to receive help.
 
C

Cheinberger

Guest
Please use the [code*] [/code*] tags (remove the asterisk) for posting code, it makes it much easier to read. No green text either.

You will be much more likely to receive help.
Changes have been made! Thank you
 
Top