1
\$\begingroup\$

I'm currently in the process of making a platformer, and am currently in the process of creating "depth" into my game, by making Up/Down-W/S control your depth. (Come closer to screen, go further).

The reason I chose to do this is so I can walk around stairs, go behind tables, etc.

But I have run into a problem.

When I call in my player code, if (depth == oWall.depth) {//code}, it is applying to every single wall ever. Is there a way to only make it apply to the object you are currently touching?

Here is my code so far:

/// Collision


// TODO: Make "depth" apply to a singular instance.
//   \/          \/
if (depth == oWall.depth) {

    /*
        Colliding with a wall on the Horizontal Axis, causes the player to stop moving.
    */

    if (place_meeting(x + h_speed, y, oWall)) {
        while(!place_meeting(x + sign(h_speed), y, oWall)) {
            x += sign(h_speed);
        }
        h_speed = 0;
    }

    /*
        Colliding with a wall on the Vertical Axis, causes the player to stop moving.
    */

    if (place_meeting(x, y + v_speed, oWall)) {
        while(!place_meeting(x, y + sign(v_speed), oWall)) {
            y += sign(v_speed);
        }
        v_speed = 0;
    }
}

Hope you understand what I'm asking.

\$\endgroup\$
0
\$\begingroup\$

You probably need to check for collision first, then check for depth. You can get the wall you are colliding with using wallHit = instance_place(.., .., oWall) then compare depth with wallHit.depth.

Since you are checking collision twice, once for movement on each axis, you will need to check twice just in case there is a different collision result in each case.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Wow. Was it really as simple as that?! Thanks alot. I appreciate it. I just changed all the if (place_meeting(...)){}'s with what you said. Thanks again. \$\endgroup\$ – user59493 Jan 28 '15 at 2:26
  • \$\begingroup\$ No problem. If you get on with visual learning, Tom Francis (creator of Gunpoint) is currently doing a video series on GameMaker "Make A Game With No Experience". It starts from no assumptions about your level in programming / GameMaker, so you may need to skip through if you're already familiar with GameMaker, but it covers a bunch of practical stuff and you may pick up some tricks. I know I did. \$\endgroup\$ – Mike Tunnicliffe Jan 28 '15 at 9:10
  • \$\begingroup\$ Haha! I've been following that from Day One! Tom Francis... Gotta love him. I did programming in Java a while back, so GML is actually quite familiar in a sense that many things are similar to Java. \$\endgroup\$ – user59493 Jan 30 '15 at 6:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy