Hi guys,
Here is the problem : I have an animated character. When he changes his direction, like left to right, it might cause some problems with the walls. Like getting stuck. Or for my ennemis (also animated just by a simple line), It can teleport them very far, until they find a wall... Also, if my character attacks (there is an animation for it) for the first time, he gets stuck and I have to jump to debug him (then I can attack as much as I want and the problem doesn't come again). Moreover, I'm getting some bugs when I jump and I try to double jump when I spam it. I'm pretty sure it might be because when I land on the wall, the variable double_jump doesn't get reset because of the collision mask and the animation things.
As you can see, a lot of bugs but I'm 90% sure it's all because of the animation cycle that doesn't work well. I don't know how to code something like this properly and maybe there are some rules for the differents sprites in animation ??
Here is my code:
Collision/Movement:
The simple line to check if my character is going left or right:
It is pretty much all but if you need anything else in my code to help me, I could put the rest !
See you soon !
Here is the problem : I have an animated character. When he changes his direction, like left to right, it might cause some problems with the walls. Like getting stuck. Or for my ennemis (also animated just by a simple line), It can teleport them very far, until they find a wall... Also, if my character attacks (there is an animation for it) for the first time, he gets stuck and I have to jump to debug him (then I can attack as much as I want and the problem doesn't come again). Moreover, I'm getting some bugs when I jump and I try to double jump when I spam it. I'm pretty sure it might be because when I land on the wall, the variable double_jump doesn't get reset because of the collision mask and the animation things.
As you can see, a lot of bugs but I'm 90% sure it's all because of the animation cycle that doesn't work well. I don't know how to code something like this properly and maybe there are some rules for the differents sprites in animation ??
Here is my code:
Collision/Movement:
Code:
//MOVEMENT PLAYER
//Calculate Movement
var move = checkKeyboard_Right - checkKeyboard_Left;
hsp = move * walkspeed;
vsp += grv;
//Jump from floor
if ( (place_meeting(x, y+1, obj_wall)) && (checkKeyboard_Jump) )
{
vsp = -8;
}
//Double Jump
if (!place_meeting(x, y+1, obj_wall) && double_jump) && checkKeyboard_Jump
{
vsp = - 8;
double_jump = false;
}
//Vertical Collision
if place_meeting(x+hsp, y, obj_wall)
{
while (!place_meeting(x + sign(hsp), y, obj_wall))
{
x += sign(hsp)
}
hsp = 0;
}
y += vsp;
//Horizontal Collision
if place_meeting(x, y + vsp, obj_wall)
{
while (!place_meeting(x, y + sign(vsp), obj_wall))
{
y += sign(vsp)
}
if !place_meeting(x, y+vsp, obj_ceiling)
{
//Reset Double Jump
if !double_jump double_jump = true;
}
vsp = 0;
}
//Movement
x += hsp;
Code:
// ANIMATION PLAYER
if hsp != 0
{
image_xscale = size * sign(hsp);
sprite_index = spr_run;
image_speed = 1;
}
See you soon !