J
Johnjack
Guest
Hi!
I'm trying to develop a simple platformer on GMS2 (version 2.2.4.374) by following Shaun Spalding tutorials.
My problem is that during the jump attack animation, the player's "y" position is blocked, as if gravity were to disappear. At the end of the animation, gravity reappears.
I use a state machine.
If someone could help, i will be thankful. Here is my oPlayer code and state machine:
create event:
Step event:
PlayerState_Free
PlayerState_Attack_Slash
PlayerState_Attack_Slash_Air (exactly the same as PlayerState_Attack_Slash)
I read that it would be necessary to create a separate script with the code concerning physics (gravity, collisions ...). Is that right?
I'm trying to develop a simple platformer on GMS2 (version 2.2.4.374) by following Shaun Spalding tutorials.
My problem is that during the jump attack animation, the player's "y" position is blocked, as if gravity were to disappear. At the end of the animation, gravity reappears.
I use a state machine.
If someone could help, i will be thankful. Here is my oPlayer code and state machine:
create event:
Code:
hsp = 0;
vsp = 0;
grv = 0.3;
jumpsp = 7;
walksp = 3;
hascontrol = true;
//for ledge assistance
grace_jump_time = 4; //number of grace period frames after leaving the ground you can still jump
grace_timer = grace_jump_time;
//for input buffering
jump_buffer = 4; //number of grace period frames between player pressing jump and hitting the ground when they will still jump
jump_buffer_timer = jump_buffer;
controller = 0;
state = PLAYERSTATE.FREE;
hitByAttack = ds_list_create();
enum PLAYERSTATE
{
FREE,
ATTACK_SLASH,
ATTACK_SLASH_AIR,
ATTACK_COMBO,
}
Code:
#region //get player input
if (hascontrol)
{
//Get the player's input
key_right = keyboard_check(vk_right);
//key_right = keyboard_check(ord("D"));
key_left = -keyboard_check(vk_left);
//original non-variable jumping
key_jump = keyboard_check_pressed(vk_space);
//for variable jumping
key_jump_held = keyboard_check(vk_space);
//for ledge assistance
is_on_ground = false;
//for jump input buffering
jump_is_inside_buffer = false;
//for attack
key_attack = keyboard_check_pressed(ord("A"));
if (key_left) || (key_right) || (key_jump)
{
controller = 0;
}
if (abs(gamepad_axis_value(0, gp_axislh)) > 0.2)
{
key_left = abs (min(gamepad_axis_value(0, gp_axislh),0))*-1;//j'ai juste rajouté le "*-1" parce qu'avec les modifications pour les ledge assistance et jump buffering, le perso allait à droite quand j'appuyais sur gauche à la manette.
key_right = max (gamepad_axis_value(0, gp_axislh),0);
controller = 1;
}
if (gamepad_button_check_pressed(0, gp_face1))
{
key_jump = 1;
controller = 1;
}
if (gamepad_button_check_pressed(0, gp_face3))
{
key_attack = 1;
controller = 1;
}
}
else
{
key_right =0;
key_left =0;
key_jump =0;
key_attack =0;
}
#endregion
switch (state)
{
case PLAYERSTATE.FREE: PlayerState_Free(); break;
case PLAYERSTATE.ATTACK_SLASH: PlayerState_Attack_Slash(); break;
case PLAYERSTATE.ATTACK_SLASH_AIR: PlayerState_Attack_Slash_Air(); break;
case PLAYERSTATE.ATTACK_COMBO: PlayerState_Attack_Combo(); break;
}
Code:
//React to inputs
move = key_left + key_right;
hsp = move * walksp;
if (vsp < 10) vsp+= grv;
//if you're on the ground, you can jump (base tutorial version)
if (place_meeting(x,y+1,oWall))
{
vsp = key_jump * -jumpsp;
}
//For Ledge Assistance with input buffering
if (place_meeting(x,y+1,oWall))
{
is_on_ground = true;
grace_timer = grace_jump_time;
}
else{
is_on_ground = false;
grace_timer--;
}
Code:
hsp = 0;
vsp = 0;
//start of the attack
if (sprite_index != sAttack_Slash)
{
sprite_index = sAttack_Slash;
image_index = 0;
ds_list_clear(hitByAttack);
}
//Use attack hitbox & check for hits
mask_index = sAttack_SlashHB;
var hitByAttackNow = ds_list_create();
var hits = instance_place_list(x,y,oEnemy,hitByAttackNow,false);
if (hits > 0)
{
for (var i = 0; i < hits; i++)
{
//if this instance has not yet been hit by this attack
var hitID = hitByAttackNow[| i];
if (ds_list_find_index(hitByAttack,hitID) == -1)
{
ds_list_add(hitByAttack, hitID);
with (hitID)
{
EnemyHit(2);
}
}
}
}
ds_list_destroy(hitByAttackNow);
mask_index = sPlayer;
if (animation_end())
{
sprite_index = sPlayer;
state = PLAYERSTATE.FREE;
}
Code:
hsp = 0;
vsp = 0;
//start of the attack
if (sprite_index != sAttack_Slash)
{
sprite_index = sAttack_Slash;
image_index = 0;
ds_list_clear(hitByAttack);
}
//Use attack hitbox & check for hits
mask_index = sAttack_SlashHB;
var hitByAttackNow = ds_list_create();
var hits = instance_place_list(x,y,oEnemy,hitByAttackNow,false);
if (hits > 0)
{
for (var i = 0; i < hits; i++)
{
//if this instance has not yet been hit by this attack
var hitID = hitByAttackNow[| i];
if (ds_list_find_index(hitByAttack,hitID) == -1)
{
ds_list_add(hitByAttack, hitID);
with (hitID)
{
EnemyHit(2);
}
}
}
}
ds_list_destroy(hitByAttackNow);
mask_index = sPlayer;
if (animation_end())
{
sprite_index = sPlayer;
state = PLAYERSTATE.FREE;
}