1
\$\begingroup\$

In old 2d games such as double dragon, streets of rage etc. where the player could move “up and down” on the y-axis to give an illusion of depth (as opposed to something like Mario) how were slopes and stairs handled along different points on the y-axis to give the appearance of still moving in a straight line?

enter image description here

For instance in the above picture would you set collision masks where the green lines are? Then imagine the characters are the red and blue lines respectively, how would you handle them in effect being moved “down” by gravity when in fact there isn’t really any gravity? For the top line I assumed when it hit the green line, rather then stopping or bouncing back on the x-axis you’d just nudge them down and continue the x movement?

I understand how this could be completed in 3D but I’m perplexed how this would’ve been achieved in purely 2d environments. Or maybe I’m imagining slopes/stairs in these old games...

I’m working in SpriteKit, so any ideas specific to that would be great but just understanding how this was accomplished theoretically in the first instance would be great.

Thanks

edit - after some thinking I don't think my 'collision' theory would work going down the slope for the blue line as it wouldn't be colliding unless it came off it's "straight" path, and also the problem would be reversed when going 'up' the slope.

enter image description here

so for instance in the above image where the characters are moving up the slope the other way I'm curious how this would have been handled? My thoughts now are, would the darker grey area with the "1" on it, actually be an entire entity itself or a collision mask? You'd then work out based on the characters "Y entry" point on to it (either at the top or the bottom) and based on their direction, where their 'Y' point should then be?

\$\endgroup\$
  • \$\begingroup\$ I used to wonder how to solve a similar problem when i tried to make an Excitebike style game. In the end I gave in and used a 3d game engine with collision (ie Unity). But on a simple 2d level, my thoughts are that the 'slopes' are all at set values on the game-worlds x axis. So if the player presses 'Up' key you would add an 'offset' to that players Y position, then include that offset amount when he hits the slope (you only need the bottom slope for it the top one isnt really there. Eg. So the blue line in ur drawing is at always at 0 offset and the red is at 2 offset for example. They.... \$\endgroup\$ – Big T Larrity Dec 7 '18 at 13:57
  • \$\begingroup\$ ...both hit the slope at the same time in reality, however the red guy will look higher up because you've added the offset of 2 (or whatever figure you require to create the spacing , depending on the scale of your gameobjects/world.). NOTE: I hope this helps somewhat, but I am also a novice programmer just thrtowing my idea in the mix. Hopefully an expert programmer can come in and enlighten both of us how to achieve this properly. :D \$\endgroup\$ – Big T Larrity Dec 7 '18 at 13:58
  • \$\begingroup\$ @SuperMegaBroBro yeah excite bike is a great example. The offset idea sounds like a good approach and should be easy enough to do actually. I might try and knock up an example \$\endgroup\$ – TommyBs Dec 7 '18 at 15:47
  • \$\begingroup\$ nice one!! glad to help with some ideas (as I say, Im still at the "trial and error" stage of game dev myself :S ) \$\endgroup\$ – Big T Larrity Dec 7 '18 at 19:03
2
\$\begingroup\$

It's really no different than sloped 2d case

Consider the following picure.

enter image description here

In this instance, to move over the ramp you would just move using the slope of the ramp. Easy right? y = mx+b kind of stuff.

Now look at this picture.

enter image description here

Notice anything different? Actually notice what really isn't different? The only thing we changed is that we extended this ramp out, but straight in one dimension.

So lets think about this, would anything change about how you moved if you started walking from the top right corner on end of the road to the top left corner of the other from the first picture to the second?

enter image description here

No, it's as if there wasn't an "extension into 3D" at all, you move the character by the same slope and same amounts as you would have in the first picture.

But what about if you moved down a bit?

enter image description here

Notice how the slope you have to move and by how much you have to move by while on the ramp does not change, and the x position where you encounter the ramp doesn't change either. So what does change? The only thing that changes is your Y position, everything else is the same.

Notice that this is the exact same scenario as the first case except the Y has changed.

Now how might one implement such a feature? There's a bunch of ways, but one way might be to assign a slope value to each tile, or something along those lines. On most tiles, your slope would be 1 x over 1 y, or 1, so your character will just move horizontally, but when it slopes, it might be 1/2, so when your character moves, x moves + 1/2 and Y moves 1/(1/2) or 2 units. If you aren't supposed to move in an area (ie to an area which may be below the ram) you could just block movement to those areas via what ever collision you have in your game.

enter image description here

I have no clue if you are using tiles or are just rendering objects or something else. If rendering objects you can just assign the slope to the object. You can use collision checks with the bottom of your character and the sloped object to figure out the slope you should be using.

enter image description here

\$\endgroup\$
  • \$\begingroup\$ Thank you @opa I guess in my head I was just making this more complicated then it needed to be thinking that I needed 'gravity' to handle the slope, when the reality is it doesn't need it as I'll be controlling the Y \$\endgroup\$ – TommyBs Dec 7 '18 at 21:36

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.