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

*Solved* Sprite can move only when airborne

firestar

Member
GML:
//Get player input
key_left = keyboard_check(vk_left);
key_right = keyboard_check(vk_right);
key_jump = keyboard_check_pressed(vk_space);


//Calculate movement
var move = key_right - key_left;
hsp = move * walkspd;
vsp = vsp + grv;
if (place_meeting(x, y+1, coolObjectWall)) && (key_jump)
{
     vsp = -4;
}

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

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


//Animation
if (!place_meeting(x, y+1, coolObjectWall))
{
    sprite_index = coolGuyJump;
    image_speed = 0;
    if (sign(vsp) > 0) image_index = 1; else image_index = 0;
}
else
{
    image_speed = 1;
     if (hsp == 0)
    {
        image_speed = 1;
        sprite_index =    coolGuy;
    }
    else
    {
        image_speed = 1;
        sprite_index = coolGuyRun;
    }
}
this is the code I am using but whenever I am on the ground I cannot move. Can anyone help me?
btw this code is an event for an object
 

firestar

Member
It means you are actually inside the ground. Make sure the Sprite Origins for each of your Sprites are set to bottom center.
thank you so much, it works now I just had to set the origins to the bottom and make them the same x and y position
 
Last edited:

chamaeleon

Member
What have the use of the debugger or show_debug_message() told you about which code path is taken and why (i.e., what were the values and expressions like that influenced it)?
Edit: Solved while I had the editor open to write this. Ignore it.
 

firestar

Member
What have the use of the debugger or show_debug_message() told you about which code path is taken and why (i.e., what were the values and expressions like that influenced it)?
I fixed this already but do I need to close this thread or mark as answered?
 
Top