Users browsing this thread: 3 Guest(s)
PBG Engine
#5
Create Event
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.
Reply
Thanked by: Joxon


Messages In This Thread
PBG Engine - by Joxon - 11-16-2014, 03:26 PM
RE: PBG Engine - by Kelvin - 11-17-2014, 08:22 AM
RE: PBG Engine - by Joxon - 11-17-2014, 04:01 PM
RE: PBG Engine - by Joxon - 11-18-2014, 10:04 PM
RE: PBG Engine - by Kelvin - 11-21-2014, 05:31 PM
RE: PBG Engine - by Joxon - 11-21-2014, 07:21 PM
RE: PBG Engine - by Kelvin - 11-22-2014, 03:22 PM
RE: PBG Engine - by Joxon - 11-22-2014, 07:41 PM
RE: PBG Engine - by Kelvin - 11-22-2014, 07:47 PM
RE: PBG Engine - by Joxon - 11-23-2014, 12:03 PM
RE: PBG Engine - by Kelvin - 11-24-2014, 08:26 AM
RE: PBG Engine - by Joxon - 11-25-2014, 09:56 PM
RE: PBG Engine - by Kelvin - 11-27-2014, 10:40 AM
RE: PBG Engine - by Joxon - 11-27-2014, 04:00 PM
RE: PBG Engine - by Kelvin - 11-28-2014, 03:53 PM
RE: PBG Engine - by Joxon - 11-29-2014, 11:40 AM
RE: PBG Engine - by Joxon - 11-30-2014, 04:03 PM
RE: PBG Engine - by Kelvin - 12-01-2014, 08:25 AM
RE: PBG Engine - by Joxon - 12-04-2014, 07:25 PM
RE: PBG Engine - by Joxon - 12-07-2014, 03:15 PM
RE: PBG Engine - by Joxon - 12-08-2014, 09:11 PM
RE: PBG Engine - by Joxon - 12-13-2014, 09:41 PM
RE: PBG Engine - by Struggleton! - 12-13-2014, 10:24 PM
RE: PBG Engine - by TheShyGuy - 12-14-2014, 02:53 PM
RE: PBG Engine - by Joxon - 12-14-2014, 05:47 PM
RE: PBG Engine - by Joxon - 12-18-2014, 09:44 PM
RE: PBG Engine - by Kelvin - 12-19-2014, 02:34 PM
RE: PBG Engine - by Joxon - 12-19-2014, 08:36 PM
RE: PBG Engine - by Joxon - 12-22-2014, 08:00 PM
RE: PBG Engine - by Kelvin - 12-23-2014, 07:56 PM
RE: PBG Engine - by Joxon - 12-23-2014, 09:57 PM
RE: PBG Engine - by Kelvin - 12-26-2014, 03:55 PM
RE: PBG Engine - by Joxon - 12-26-2014, 05:30 PM
RE: PBG Engine - by Kelvin - 12-26-2014, 06:02 PM
RE: PBG Engine - by Joxon - 12-26-2014, 09:50 PM
RE: PBG Engine - by Kelvin - 12-26-2014, 10:41 PM
RE: PBG Engine - by Joxon - 12-27-2014, 08:58 AM
RE: PBG Engine - by Kelvin - 12-27-2014, 08:06 PM
RE: PBG Engine - by Joxon - 12-31-2014, 08:35 PM
RE: PBG Engine - by TheShyGuy - 12-31-2014, 10:31 PM
RE: PBG Engine - by Joxon - 12-31-2014, 11:11 PM
RE: PBG Engine - by Kelvin - 12-31-2014, 11:30 PM
RE: PBG Engine - by Joxon - 01-06-2015, 08:51 PM
RE: PBG Engine - by Joxon - 01-09-2015, 04:03 PM
RE: PBG Engine - by Kelvin - 01-10-2015, 07:13 PM
RE: PBG Engine - by Joxon - 01-10-2015, 09:44 PM
RE: PBG Engine - by Kelvin - 01-11-2015, 10:32 AM
RE: PBG Engine - by Joxon - 01-11-2015, 02:04 PM
RE: PBG Engine - by Kelvin - 01-12-2015, 08:55 AM
RE: PBG Engine - by Joxon - 01-12-2015, 05:28 PM
RE: PBG Engine - by Dazz - 01-16-2015, 02:08 AM
RE: PBG Engine - by Joxon - 01-16-2015, 06:08 PM
RE: PBG Engine - by Joxon - 01-17-2015, 08:10 PM
RE: PBG Engine - by Joxon - 01-19-2015, 09:45 PM
RE: PBG Engine - by Joxon - 01-21-2015, 08:48 PM
RE: PBG Engine - by Joxon - 01-25-2015, 09:41 PM
RE: PBG Engine - by Kelvin - 01-26-2015, 02:23 PM
RE: PBG Engine - by TheShyGuy - 01-26-2015, 03:35 PM
RE: PBG Engine - by Joxon - 01-31-2015, 05:16 PM
RE: PBG Engine - by TheShyGuy - 01-31-2015, 05:51 PM
RE: PBG Engine - by Joxon - 02-07-2015, 11:36 AM
RE: PBG Engine - by TheShyGuy - 02-07-2015, 12:12 PM
RE: PBG Engine - by Kelvin - 02-07-2015, 11:24 PM
RE: PBG Engine - by Joxon - 02-08-2015, 03:40 PM
RE: PBG Engine - by Kelvin - 02-09-2015, 08:12 AM
RE: PBG Engine - by Joxon - 02-09-2015, 04:40 PM
RE: PBG Engine - by Kelvin - 02-09-2015, 08:31 PM
RE: PBG Engine - by Joxon - 02-10-2015, 09:59 PM
RE: PBG Engine - by Joxon - 02-18-2015, 10:03 PM
RE: PBG Engine - by Kelvin - 02-19-2015, 12:33 PM
RE: PBG Engine - by Joxon - 02-19-2015, 04:13 PM
RE: PBG Engine - by Kelvin - 02-20-2015, 04:17 PM
RE: PBG Engine - by Joxon - 03-08-2015, 08:28 PM
RE: PBG Engine - by Jaharl - 03-08-2015, 08:40 PM
RE: PBG Engine - by Joxon - 03-08-2015, 09:19 PM
RE: PBG Engine - by Jaharl - 03-08-2015, 09:39 PM
RE: PBG Engine - by Kelvin - 03-09-2015, 01:29 PM

Forum Jump: