GMS 2 Character is off set in game

This is my second game i've tried to make and they have both had this problem. I gave up on the first one because it wasnt important to me. This one though I am going all the way through. When I made the collisions everything worked.
It looked like this:
Code:
/// @description Physics

//Keys
key_left = keyboard_check(ord("A"));
key_right = keyboard_check(ord("D"));
key_jump = keyboard_check_pressed(vk_space);

//Movement
var move = key_right - key_left;

hsp = move * walksp;

vsp = vsp + grv;

if (place_meeting(x,y+1,Obj_Wall)) and (key_jump){
    
    vsp = -7;
}

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

//Verticalcollision
if (place_meeting(x,y+vsp,Obj_Wall)){
    
    while (!place_meeting(x,y+sign(vsp),Obj_Wall)){
        
        y = y + sign(vsp);
    }
    vsp = 0;
    
}
y = y + vsp;
upload_2020-1-12_17-2-24.png

But then I added Animations and this happened:
Code:
/// @description Physics

//Keys
key_left = keyboard_check(ord("A"));
key_right = keyboard_check(ord("D"));
key_jump = keyboard_check_pressed(vk_space);

//Movement
var move = key_right - key_left;

hsp = move * walksp;

vsp = vsp + grv;

if (place_meeting(x,y+1,Obj_Wall)) and (key_jump){
    
    vsp = -7;
}

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

//Verticalcollision
if (place_meeting(x,y+vsp,Obj_Wall)){
    
    while (!place_meeting(x,y+sign(vsp),Obj_Wall)){
        
        y = y + sign(vsp);
    }
    vsp = 0;
    
}
y = y + vsp;

//Animation
if(!place_meeting(x,y+1,Obj_Wall)){
    
    sprite_index = Spr_PlayerAir;
    image_speed = 0;
    if (sign(vsp) > 0) image_index = 1; else image_index = 0;


}
upload_2020-1-12_17-4-18.png

Why did it do this and how can I fix it.
 

Attachments

TheouAegis

Member
You need to verify your sprites all have the same bounds-to-origin settings. If your origin is, say, four pixels above the bottom bounds of your Sprite in one Sprite, then it needs to be four pixels above the bottom of the bounds of every other Sprite. Otherwise, when you change Sprite you will end up at different points.
 
You need to verify your sprites all have the same bounds-to-origin settings. If your origin is, say, four pixels above the bottom bounds of your Sprite in one Sprite, then it needs to be four pixels above the bottom of the bounds of every other Sprite. Otherwise, when you change Sprite you will end up at different points.
yes I had to change my Sprite origin and now it looks great, thanks for the help
 
Top