Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411431 Posts in 69363 Topics- by 58416 Members - Latest Member: JamesAGreen

April 20, 2024, 03:29:16 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Jump-Through Platforms (SOLVED)
Pages: [1]
Print
Author Topic: Jump-Through Platforms (SOLVED)  (Read 2607 times)
Zack Bell
Level 10
*****



View Profile WWW
« on: October 10, 2013, 11:39:07 AM »

Typically, when starting a platformer prototype in Game Maker, I whip out a few scripts that I've come to love from Matt Thorsen's Grandma Engine.

One of the scripts checks to see if the player is on the ground, as well if the player is on top of a platform, but not colliding with a platform. This handles both solid ground and jump-throughs (to a certain extent).

Code:
// Original code with names changed to suit my project
return place_meeting(x, y + 1, oParentFloor)
    || (place_meeting(x, y + 1, oParentPlatform) && !place_meeting(x, y, oParentPlatform));

Simple, but you can't stand on a platform while colliding with a different platform. Say you
use them as stepping stones and the player or an enemy is taller than two platforms that are stacked. Hopefully that makes sense?

So basically, I need to check if you're standing on a platform and not colliding with that same platform. I have come up with several ways to do it that work in 'most' cases. I also came up with a way to do it that seems very slow and troublesome (but it works).
 
Code:
// Slow, but useful
with (oParentPlatform) {
    if (place_meeting(x, y - 1, other) && !place_meeting(x, y, other))
        with (other)
            if (place_meeting(x, y + 1, other))
                return true;
}

return place_meeting(x, y + 1, oParentFloor);

Any advice on ways to do it differently or speed it up?

EDIT: For example, I can use instance_place() to return the ID of the platform I'm standing on and compare that to the platform I am colliding with. There are issues with that though; the big one being that instance_place() returns the first instance and you could be colliding with several. That is where I got the idea to step through the platforms with with().
« Last Edit: October 10, 2013, 02:09:05 PM by Zack Bell » Logged

ThemsAllTook
Administrator
Level 10
******



View Profile WWW
« Reply #1 on: October 10, 2013, 12:32:13 PM »

I'm not sure how this would work in Game Maker, but the way I normally do this is to keep an onGround boolean for each moving game object affected by gravity, set it to false right before collision detection, and set it to true when a downward collision is detected. When you're standing on the ground, you're continuously colliding with it every frame due to gravity, so it gets set back to true right away in that case. If you walk off the edge of a platform, since it's assumed to be false before collision detection is run, it stays false since there's no longer solid ground under you. When you jump, you'd of course manually set it to false.
Logged

Zack Bell
Level 10
*****



View Profile WWW
« Reply #2 on: October 10, 2013, 01:53:06 PM »

Sorry, maybe I wasn't super clear. I do have an onGround variable. Every frame I do the following:

Code:
onGround = CheckOnGround();

// CheckOnGround() being the code snippets that I posted in the OP

This shitty paint art demonstrates the abilities and disadvantages of the first way of doing things (Grandma Engine).



The third player on the right is standing on a platform, but also colliding with a separate platform. This causes him to fall through the bottom platform as well.
Logged

ஒழுக்கின்மை (Paul Eres)
Level 10
*****


Also known as रिंकू.


View Profile WWW
« Reply #3 on: October 10, 2013, 02:01:59 PM »

i'd use collision_line -- imagine an invisible line under the player, like right at his feet. check that line's collision with platforms. the code you are using checks the *player's* collision with platforms
Logged

Zack Bell
Level 10
*****



View Profile WWW
« Reply #4 on: October 10, 2013, 02:08:53 PM »

Lol, dammit. That is why I asked you. This works perfectly.

Code:
var platformBelow, platformCollide;

platformBelow   = collision_line(bbox_left, bbox_bottom + 1, bbox_right, bbox_bottom + 1, oParentPlatform, true, false);
platformCollide = instance_place(x, y, platformBelow);

return place_meeting(x, y + 1, oParentSolid) || (platformBelow && (platformCollide != platformBelow));

Thank you, sir  Coffee
Logged

robageejammin
Level 0
*


View Profile
« Reply #5 on: February 17, 2019, 11:25:16 PM »

Hey there!

Having the same issue here where walking into a platform while standing on a different one drops me down, but having trouble applying the above solution to my current setup. Here's what I currently have for vertical platform collisions (based on a Shaun Spalding tutorial).

Code:
if vsp >0 && place_meeting(x,y+vsp,plat) && !place_meeting(x,y,plat)
{
    while(!place_meeting(x,y+sign(vsp),plat))
    {
        y += sign(vsp);
    }
    vsp = 0;
}

y += vsp;

Sorry if it is obvious, but do you think the same solution would apply here, and how do you think it would fit? Any help would be greatly appreciated, thanks!
Logged
robageejammin
Level 0
*


View Profile
« Reply #6 on: February 18, 2019, 07:27:35 PM »

Scratch that! Came up with a slightly different solution that I really like! Here it is below if it can help anyone.

Code:
//Collision with Platform
//Checks for collision from player's feet through where player's feet will be next frame
if vsp >0 && collision_rectangle(bbox_left,bbox_bottom+1,bbox_right,bbox_bottom+1+vsp,plat,0,1)
{
    //while loop: If there is no platform 1 pixel underneath, player will move down 1 pixel
    while(!collision_line(bbox_left,bbox_bottom+sign(vsp),bbox_right,bbox_bottom+sign(vsp),plat,0,1))
    {
        y += sign(vsp);
    }
    vsp = 0;
}
y += vsp;

//IMPORTANT: Platform mask must be 1 pixel in height for this method to work

Put it through rigorous testing and seems very reliable so far. As an added bonus, it also won't let your player fall through a platform if its falling too fast since it is taking vsp (or whatever your vertical speed variable is) into account.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic