S
Samus
Guest
I'm using Game Maker Studio's built in Physics engine to make a platformer game. Usually I use my own engine, but I decided to experiment with the one that's already there. I have two objects: obj_ground and obj_mario. Both objects have rectangle fixtures, and to make the player move I apply a force to it based on Key input. I place multiple ground blocks in the room to make the floor, and have put some more blocks elevated above the other ones so you can jump on them if desired. Strangely, moving Mario will occasionally result in him getting stuck on one of the ground blocks, even though they are all level and moving backwards and then moving forwards again will let you pass. Also, jumping on top of one of the elevated blocks and then falling off of them will result in Mario being suspended a few pixels above the ground. He can still move, but he can't jump. Here is some code:
None of the objects are solid, they have friction and Mario has density, all other values are 0. This doesn't make any sense to me and I can't find any documentation that helps. Thank you in advance!
Code:
///Mario step event
var hori = -keyboard_check(vk_left) + keyboard_check(vk_right);
physics_apply_force(x, y, hori * 30, 0);
if(keyboard_check(vk_shift))
{
if(phy_speed_x > 2 * speed_limit) phy_speed_x = 2* speed_limit;
if(phy_speed_x < -2 * speed_limit) phy_speed_x = -2 * speed_limit;
if(hori != 0)
{
image_xscale = hori;
sprite_index = spr_MarioNESRunning
}
else sprite_index = spr_MarioNES
}
else
{
if(phy_speed_x > speed_limit) phy_speed_x = speed_limit;
if(phy_speed_x < -speed_limit) phy_speed_x = -speed_limit;
if(hori != 0)
{
image_xscale = hori;
sprite_index = spr_MarioNESWalking
}
else sprite_index = spr_MarioNES
}
if(jump = 1)
{
sprite_index = spr_MarioNESJumping;
if(place_meeting(x, y + 1, obj_ground)) && (time = 1) jump = 0;
}
if(sign(phy_speed_x) != hori) && (hori != 0) && (jump = 0) && (!place_meeting(x + hori, y, obj_ground)) sprite_index = spr_MarioNESTurn;
Code:
//Mario Key space event
if(place_meeting(x, y + 1, obj_ground))
{
physics_apply_force(x, y, 0, -300);
jump = 1;
alarm_set(0, 2);
time = 0;
}
Code:
///Mario Alarm zero
time = 1;