thandwiches01
Member
I am having trouble with my 2D platformer.
There seems to be some problem with my collision.
About 40% of the time my player object lands, it appears that he is half a pixel in the air, instead of being at the same level as the ground.
When the player moves horizontally, he has a chance of, when touching the sides, stopping right before the wall, and stopping while inside the wall. I made sure to have my movement speeds set to be an even number, just to make sure its not a problem with it not colliding correctly.
I have all my sprites centered the same, so i am not exactly sure what is going on.
The way I have my player object, is so that I have a different sprite for the different movements. for example: walking, jumping, idle. I also have a collision mask for the player, and all the different movement sprites are based on that sprite size.
So, in my mind, there shouldn't be any problem. but I recently came back to Gamemaker after taking a break for a year or so. so I am not sure if I am just being really dumb.
Here is my code:
Create
Step:
Collision with collision parent:
There seems to be some problem with my collision.
About 40% of the time my player object lands, it appears that he is half a pixel in the air, instead of being at the same level as the ground.
When the player moves horizontally, he has a chance of, when touching the sides, stopping right before the wall, and stopping while inside the wall. I made sure to have my movement speeds set to be an even number, just to make sure its not a problem with it not colliding correctly.
I have all my sprites centered the same, so i am not exactly sure what is going on.
The way I have my player object, is so that I have a different sprite for the different movements. for example: walking, jumping, idle. I also have a collision mask for the player, and all the different movement sprites are based on that sprite size.
So, in my mind, there shouldn't be any problem. but I recently came back to Gamemaker after taking a break for a year or so. so I am not sure if I am just being really dumb.
Here is my code:
Create
Code:
move = 0;
movespeed = 4;
jumpspeed = -2;
grav = 0.125;
facing = 1;
Code:
image_xscale = facing;
left = keyboard_check(vk_left);
right = keyboard_check(vk_right);
up = keyboard_check_pressed(vk_up);
if left || right && !place_free(x, y + 1) { sprite_index = spr_player_walk; image_speed = 0.25};
if move == 0 && gravity == 0 { sprite_index = spr_player_idle; image_speed = 0.025};
move = -(left - right);
x += (move * movespeed) * place_free(x + move * movespeed, y);
if up { vspeed = jumpspeed }
if place_free(x, y + 1)
{
sprite_index = spr_player_jump
gravity = grav;
} else {
gravity = 0;
}
if move != 0 then facing = move;
Code:
if hspeed != 0 then hspeed = 0;
if vspeed != 0 then vspeed = 0;