Create Event
Step Event
"move" Script
"hitFloor" Script
The Floor object is the type of platform you can pass through. The height of the Floor's sprite does not matter, since this script checks if the sprite is above and only above the Floor. If you're using collision masks, it may be wise to substitute sprite height for the sprite's bounding box's lower edge.
Hope that solves your physics problems. Let me know if you have any trouble, and I'll see if I can fix it.
[EDIT AFTER PLAYING NEW BUILD]
I've noticed a few issues. One, when you get hurt, you always get pushed to the right. When mixed with walking, you can move right very fast. You should set it to push against the player's current direction, which I keep track of using a variable called "facing" which is 1 for right and -1 for left. Not only does this give me something to multiply the knockback speed by, but I can also multiply the image_xscale of the player by that so I don't have to make left-facing sprites. Two, when you die, the camera just goes off and freezes for a second, and it made me think I broke the game.
Code:
xSpeed = 0;
ySpeed = 0;
Step Event
Code:
if(xSpeed > 0 && (!place_free(x, y + 1) || hitFloor(x, y + 2))) xSpeed -= 0.5; //If xSpeed is greater than 0, lower it.
if(xSpeed < 0 && (!place_free(x, y + 1) || hitFloor(x, y + 2))) xSpeed += 0.5; //If it's lower than 0, raise it.
if(xSpeed < 0.5 && xSpeed > -0.5) xSpeed = 0; //If xSpeed is stuck bouncing back and forth around 0, set it to 0.
if(place_free(x, y + 1) && !hitFloor(x, y + 2)) ySpeed += 1; //If the player is off the ground, increase ySpeed,
else if(ySpeed > 0 && (!place_free(x, y + 1) || hitFloor(x, y + 2))) ySpeed = 0; //else, set ySpeed to 0.
move(xSpeed, ySpeed); //See move script.
"move" Script
Code:
/*First we get a couple variables.
h is horizontal movement.
v is vertical movement.*/
h=argument0;
v=argument1;
/*Now what we do is instead of checking if a point is free a certain distance away,
we check every pixel ahead and then move a pixel until the loop runs out or we hit
a solid object.
i has to be absolute because if the speed is negative, it will cause the loop to
break, and we don't want that.*/
for(i=abs(h); i>0; i-=1){
if(!place_free(x, y+1) && place_free(x+(h/abs(h)),y+1) && !hitFloor(x+(h/abs(h)), y+1) && x+(h/abs(h)) > 0 && x+(h/abs(h)) < room_width && !instance_place(x, y + 1, Floor)){
x += h/abs(h);
y += 1;
}
else
if(!place_free(x, y+1) && place_free(x+(h/abs(h)),y-1) && !hitFloor(x+(h/abs(h)), y+1) && !place_free(x+(h/abs(h)),y) && x+(h/abs(h)) > 0 && x+(h/abs(h)) < room_width){
x += h/abs(h);
y -= 1;
}
else
if(place_free(x+(h/abs(h)),y) && x+(h/abs(h)) > 0 && x+(h/abs(h)) < room_width) x+=h/abs(h)
else break;
};
for(i=abs(v); i>0; i-=1){
if(place_free(x,y+(v/abs(v))) && !hitFloor(x, y + (v/abs(v) + 1))) y+=v/abs(v)
else break;
};
"hitFloor" Script
Code:
if(instance_exists(Floor)){
if(instance_place(argument0, argument1 - 1, Floor)){
var c;
c = instance_place(argument0, argument1 - 1, Floor);
if(y + (sprite_get_height(sprite_index) / 2) < c.y + 1) return 1;
else return 0;
} else return 0;
} else return 0;
The Floor object is the type of platform you can pass through. The height of the Floor's sprite does not matter, since this script checks if the sprite is above and only above the Floor. If you're using collision masks, it may be wise to substitute sprite height for the sprite's bounding box's lower edge.
Hope that solves your physics problems. Let me know if you have any trouble, and I'll see if I can fix it.
[EDIT AFTER PLAYING NEW BUILD]
I've noticed a few issues. One, when you get hurt, you always get pushed to the right. When mixed with walking, you can move right very fast. You should set it to push against the player's current direction, which I keep track of using a variable called "facing" which is 1 for right and -1 for left. Not only does this give me something to multiply the knockback speed by, but I can also multiply the image_xscale of the player by that so I don't have to make left-facing sprites. Two, when you die, the camera just goes off and freezes for a second, and it made me think I broke the game.