• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

Windows A huge shift occurs when moving a character left and right

khaledzaw

Member
Here is the code:
Create:
hsp = 0;
vsp = 0;
grv = 0;
walksp = 10;

Step:
key_left = keyboard_check(vk_left) || keyboard_check(ord("A"));
key_right = keyboard_check(vk_right) || keyboard_check(ord("D"));

//Calculate Movement
var move = key_right - key_left;

hsp = move * walksp;

vsp = vsp + grv;

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

//Horizental Collision
x = x + hsp;

//Animation

image_speed = 1;
if (hsp == 0)
{
sprite_index = ZawS;
}
else
{
sprite_index = ZawW;
}







The Difference between the two positions showed in the .png attached to the thread is just one click.
 

Attachments

Amon

Member
What is the pivot set to in the sprite editor?

Double-click on your sprite in the Hierarchy and set the origin to middle center or bottom center.
 
Top