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

My glitchy character

A

Adrianz

Guest
So, I am an inexperienced coder. My character keeps on moving weirdly. My problem in particular is that it keeps on teleporting whenever I use the arrow keys.
Please help, thx :D.
Here is the code, I do hope somebody could help me fix it.
 

Attachments

Check if your offsets for your sprite are all the same, also make sure your "spr_matthew_down" is the correct name of the sprite, or else you will be assigning a non-existent sprite to your object. Also, your movement logic for incrementing and decrementing variables is incorrect. You are making your player go down when you press left.

I have fixed your code below:

Code:
if (keyboard_check(vk_left))
{
    sprite_index = spr_matthew_left;
    x-=1;
}

if (keyboard_check(vk_right))
{
    sprite_index = spr_matthew_right;
    x+=1;
}

if (keyboard_check(vk_up))
{
    sprite_index = spr_matthew_up;
    y-=1;
}

if (keyboard_check(vk_down))
{
    sprite_index = spr_matthew_down; //fix this? Your syntax highlighting is indicating there is no sprite by this name
    y+=1;
}

What do you mean by teleporting? In what event is your code?
 
Last edited:
A

Adrianz

Guest
Check if your offsets for your sprite are all the same, also make sure your "spr_matthew_down" is the correct name of the sprite, or else you will be assigning a non-existent sprite to your object. Also, your movements for incrementing and decrementing variables are incorrect. You are making your player go down when you press left.

I have fixed your code below:

Code:
if (keyboard_check(vk_left))
{
    sprite_index = spr_matthew_left;
    x-=1;
}

if (keyboard_check(vk_right))
{
    sprite_index = spr_matthew_right;
    x+=1;
}

if (keyboard_check(vk_up))
{
    sprite_index = spr_matthew_up;
    y-=1;
}

if (keyboard_check(vk_down))
{
    sprite_index = spr_matthew_down; //fix this? Your syntax highlighting is indicating there is no sprite by this name
    y+=1;
}

What do you mean by teleporting? In what event is your code?
ok thx will try to find the flaws, and i just found out what caused the random teleportations... It's just because I didn't set the character to walk properly so it teleported back to it's original place.
 
Last edited by a moderator:
Top