collision and animation trouble

i followed Shuan spalding tutorial for platform collision and my character object keeps getting stuck on the corners of 2 meeting walls. i am also having trouble with animations, for some reason my run animation always shows instead of walking and go off for a split second while in air. i pretty sure i have written the codes to check for that. sorry for the bad explanation i'm still new to coding with out drag and drop. thanks in advance


create event:
Code:
global.GP = gamepad_is_supported();

///variables
global.levelcomplete=0
rsp=room_speed
global.Health=100
lives=3
global.points=0

//powerups
 wreker=false
 crusher=false
 elctro=false
 pyro=false
 springtail=false
//movment vars
vsp=0;
hsp=0;
grav=0.5;
jumpspeed=7;
movespeed=2;
run=false;
hurt=false;
djump=false;
longjump=false;


//aimation vars
facing=image_xscale;
face=1
inair=false;
idle=false;
walk=true;
run=false;
ground=false;
highfall=false;
nearedge=false;


Step event
Code:
/// Movment
//inputs
key_right = keyboard_check(vk_right) or gamepad_button_check(0, gp_padr);
key_left = keyboard_check(vk_left) or gamepad_button_check(0, gp_padl);
key_up =  keyboard_check(vk_up) or gamepad_button_check(0, gp_padu);
key_down = -keyboard_check(vk_down) or gamepad_button_check(0, gp_padd);
key_jump =  keyboard_check_pressed(ord("Z"))or gamepad_button_check_pressed(0, gp_face1);
key_run =   keyboard_check(ord("X"))or gamepad_button_check(0, gp_face2) {run=true}
// react to inputs
var move = key_right - key_left;
if hsp && vsp=move {idle=true};
if hsp && vsp=!move {idle=false};

// Horizontal movment
hsp = move * movespeed;
if key_run &&inair= false
{
hsp = move * movespeed *1.5;
walk=false;
}
else
{
    
    
hsp=move * movespeed;
walk=true;

}



// gravity
if (vsp < 10) vsp += grav;

// jumping
if (key_jump && place_meeting(x, y+1, obj_wall))


{
 
 vsp = -jumpspeed;
;
}
if key_jump
{
if (vsp>-jumpspeed)&&djump =true

{

vsp =  -jumpspeed;
djump=false;
}
}

//vertical motion

if ground=true
 
{
 inair=false;
 highfall=false;
    
 }
 
// horizontal collision
if (place_meeting(x + hsp, y, obj_wall))
{
    while (!place_meeting(x + sign(hsp), y, obj_wall))
    {
        x += sign(hsp);       
    }
    hsp = 0;
    
}

x+=hsp;

// vertical collision
if (place_meeting(x, y + vsp, obj_wall))
{
    while (!place_meeting(x, y + sign(vsp), obj_wall))
    {
        y += sign(vsp);
        
    }
    
    vsp = 0;
    ground = true;
    djump=true;
 
    
}

 
 y+=vsp;




// animation inputs


if key_left

{
    image_xscale=-1;
    


}


if key_right

{
    image_xscale =1;


}


if inair= true
{
walk=false;
ground=false;
run=false;

}

// animation

if ground=true&&idle=true
{
sprite_index=sp_tal_stand;
image_speed=.5;

}

///jump up animation
if
vsp < 0
{
inair=true;   

sprite_index=sp_tal_jump;
image_speed=1;


}

///falling animation
if
vsp > 0
    
{
    
inair=true;

sprite_index=sp_tal_fall;
image_speed=1;

{

    
    alarm[2]=rsp*2;}


}





// WALL/RUN ANIMATIONS

if
(key_right)&& (inair=false)
    
        
{   

if run =true
{
sprite_index=sp_taleep_run;
image_speed=1;
}
 else

if walk =true
{
sprite_index=sp_taleep_walk;
image_speed=1;
}

}





if
(key_left)&&(inair=false)


{   


if run =true
{
sprite_index=sp_taleep_run;
image_speed=1;
}
 else

{
if walk =true
sprite_index=sp_taleep_walk;
image_speed=1;
}

}
 

Tommah

Member
I think you're trying to track too many variables. For instance, isn't ground=true and inair=false the same thing? Things like that get to be really hard to track. I'll continue to look at the code but that is my first input.

*Edit*
This part does not look correct to me, I may be misunderstanding what you're using the idle variable for but it just jumped out at me...
Code:
// react to inputs
var move = key_right - key_left; //-1 if left, 1 if right
if hsp && vsp=move {idle=true};
if hsp && vsp=!move {idle=false};
Code:
if hsp && vsp=move {idle=true};
if hsp = positive and vpd = move (-1,0, or 1) then you are idling... shouldn't check if hsp AND vspd = 0 then you are idling?

Code:
if hsp && vsp=!move {idle=false};
if hsp = positive and vsp does NOT = move then you are not idling... hsp can be a negative number (moving left) and you would still be moving, correct?
vsp as long as you are not press left or right, you are not idling.... meaning you can still jump and be idle?

Again you might be changing this later in the code, I'm not sure but you really shouldn't have to. Here is what I would put...
Code:
if (hsp==0 && vsp==0) idle=true;
else if (hsp!=0 || vsp!=0) idle=false;
if hsp and vsp are both 0 then you are idling, if hsp OR vsp do NOT = 0 you are not idle.
 
Last edited:

3dgeminis

Member
If one way does not work try another. Clear the code and start again.
First start with collisions, just use 2 sprites, a simple one to see the character and the other for the collision mask (this is important).
Once the collisions work well, start adding the other sprites.
 
If one way does not work try another. Clear the code and start again.
First start with collisions, just use 2 sprites, a simple one to see the character and the other for the collision mask (this is important).
Once the collisions work well, start adding the other sprites.
I'll give it a shot thanks
 
Top