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

Legacy GM Need help coding the punch mechanic!

Liam Earles

Member
I really need help right now with this character I'm doing for my game, and it's getting very frustrating. I'm trying to code Idle, Walk, Jump and Punch animations together, but with one of the playable characters it's not working. Every time I crouch (Which is a cartwheel technique BTW), and punch it doesn't quite register.

Here's the create event:
Code:
view_object[0]=id

///Initialize Variables
image_speed=0.04
key_left = 0;
key_right = 0;

movespeed = 0;
grav = 0.5;
hsp = 0;
vsp = 0;
jumpspeed = 10.2;
movespeed = 7;
key_left = 0;
key_right = 0;
move = key_right - key_left;
hit=false
crouching=false
attack = 0
invincible = false
dead=false
suit=0
depth = -y;
invincibility=false
grounded=true

audio_listener_position(x, y, 0);
Here's the Step Event:
Code:
//Get the player's input
key_right = keyboard_check(vk_right)
key_left = -(keyboard_check(vk_left))
key_jump = keyboard_check(ord("X"))

//React to inputs
move = key_left + key_right;
hsp = move * movespeed;
if (vsp < 10) vsp += grav;

if (place_meeting(x,y+1,BrownBlock))
{
    vsp = key_jump * -jumpspeed
}

if !place_meeting(x, y+1, BrownBlock)
and key_jump
and ((place_meeting(x+1, y, BrownBlock)) or (place_meeting(x-1, y, BrownBlock)))
{
    vsp = -jumpspeed;
}

//Horizontal Collision
if (place_meeting(x+hsp,y,BrownBlock))
{
    while(!place_meeting(x+sign(hsp),y,BrownBlock))
    {
        x += sign(hsp);
    }
    hsp = 0;
}
x += hsp;

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

if (invincibility > 0){
invincibility --;
}

if place_meeting(x+1,y,BottomHalfBlackBlock)
{
grav = 0
}

if !place_meeting(x+1,y,BottomHalfBlackBlock)
and keyboard_check(vk_down)
{
grav = 0.5
}

if place_meeting(x+1,y,BottomHalfGreenBlock)
{
vsp = -12.5
}

if hit=true
{
health -=0
}

if invincible=true
{
health -=0
}

if (move !=0) image_xscale = move
if place_meeting(x,y+1,BrownBlock)
{
    if (move !=0) sprite_index=sprite_AvaRight; else sprite_index=sprite_AvaStanding
}
else
{
    if (vsp < 0) sprite_index=sprite_AvaJump else sprite_index=sprite_AvaStanding
}
if grounded=false
    if place_meeting(x+1,y,BrownBlock) or place_meeting(x-1,y,BrownBlock)
    sprite_index=sprite_AvaOnWalls
Here's the Z press Event:
Code:
if crouching=false
{
sprite_index=sprite_AvaKick
image_speed=0.4
}

if sprite_index=sprite_AvaSpinTechnique
{
sprite_index=sprite_AvaSpinKick
image_speed=0.4
}
attack = 1
And here's the down press event:
Code:
sprite_index = sprite_AvaSpinTechnique
image_speed=1
crouching=true

if keyboard_check(ord("Z"))
{
sprite_index=sprite_AvaSpinKick
image_speed=0.4
}
attack = 1
 
Top