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

GameMaker weird glitch

Kirbeh

Member
Ok so, I'm kind of new to coding and, obviously, tweaking and debugging.
So I've been following Shaun Spalding's tutorials. It seems they are pretty flawed for me though, but this far in I can't exactly switch to a new one.
So, his collision scripts were nowhere near loop-proof, so I managed to find a modification to change that.
But now I'm having a new issue. When my character walks, it glitches for a moment and gets stuck, and I have to jump to return to normal. When it walks into a wall, it glitches slightly into it.
Here's the code for more detail;
GML:
///a (irrelevent here)
key_left = keyboard_check(ord("A"));
key_right = keyboard_check(ord("D"));
key_jump = keyboard_check_pressed(ord("W"));
///b
var move = key_right - key_left;

hsp = move * walksp;

vsp = vsp + grv;

if (place_meeting(x,y+1,oWall)) && (key_jump)
{
    vsp = -9;
    onthefloor = 1;
}

if (place_meeting(x + hsp, y, oWall)) {
   repeat (abs(hsp) + 1) {
      if (place_meeting(x + sign(hsp), y, oWall))
         break;
      x += sign(hsp);
   }
   hsp = 0;
}

x += hsp;

if (place_meeting(x, y + vsp, oWall)) {
   repeat (abs(vsp) + 1) {
      if (place_meeting(x, y + sign(vsp), oWall))
         break;
      y += sign(vsp);
   }
   vsp = 0;
}

y += vsp;
//animation
if (!place_meeting(x,y+1, oWall))
{
    sprite_index = player3;
    image_speed = 0;
    if (sign(vsp) > 0) image_index = 1; else image_index = 0;

}

else
{
image_speed = 1;
if hsp == 0
    {
        sprite_index = player12;
    }

else {
    sprite_index = player;
}
}
Idk where the error is, so help is greatly appreciated.
 

TsukaYuriko

☄️
Forum Staff
Moderator
What is your mask setup? Do you have an explicitly defined mask, or does it just follow the bounding box of whatever sprite you assign to it? If so, use an explicitly defined mask so your bounding boxes don't jump all over the place, and also check your origins across all related sprites to make sure they align.
 

Kirbeh

Member
What is your mask setup? Do you have an explicitly defined mask, or does it just follow the bounding box of whatever sprite you assign to it? If so, use an explicitly defined mask so your bounding boxes don't jump all over the place, and also check your origins across all related sprites to make sure they align.
idk what the mask even is
 

Kirbeh

Member
Then your instinctive reaction should be to look it up in the manual:
sorry for the late reply. it turns out this was occurring because the origin was at the center of the sprite for some reason. It's fixed now, but there is a couple other issues i forgot to mention.
1. character spawns in ground when an object on another layer is set to its x and y
and 2. image_xscale to flip the character when moving left or right causes it to teleport in that direction by its x width (64 px)
 

TsukaYuriko

☄️
Forum Staff
Moderator
sorry for the late reply. it turns out this was occurring because the origin was at the center of the sprite for some reason. It's fixed now
If you fix the original issue by only fixing the origins, you're at the same time signing a contract that you will ensure that the origin of all sprites this instance ever has assigned to it will all line up and that all of its bounding boxes will be properly sized (whether that is identically or in a way that otherwise makes sense for them). This also opens up a lot of possibilities for you to mess it up and thus introduce more bugs of this kind. You can save yourself this trouble by assigning a dedicated mask, where you define and assign one mask and it counts regardless of which sprite is assigned.

1. character spawns in ground when an object on another layer is set to its x and y
What is the relevant code of this interaction? How does the presence of such an instance (not object) affect the player?

and 2. image_xscale to flip the character when moving left or right causes it to teleport in that direction by its x width (64 px)
Sprites rotate and flip around their origin. Set up the origins in a way that makes this transformation look natural.
 
Top