AuthorTopic: Topdown Gravity  (Read 2274 times)

Offline Mysli

  • 0001
  • *
  • Posts: 18
  • Karma: +0/-0
    • View Profile

Topdown Gravity

on: June 03, 2017, 11:56:59 am
Okay, so I'm making a game and I can't figure out how to apply gravity to the sprites, since it's a topdown game, not a platformer ;D. If you have any experience in topdown games or just want to tell your opinion, please do so!

Just a kid who wants to make games for living <3

Offline eishiya

  • 0100
  • ***
  • Posts: 1266
  • Karma: +2/-0
    • http://pixeljoint.com/p/28889.htm
    • View Profile
    • Website

Re: Topdown Gravity

Reply #1 on: June 03, 2017, 01:57:06 pm
3/4 view games like this don't usually have gravity and jumping is usually just a fixed motion in place. What's your gameplay involving gravity?

In 3/4-view, the y dimension is both north/south and up/down. Usually, the up/down is just cosmetic (e.g. using cliff tiles instead of flat ground tiles).

You can make use of y = up/down by applying jump physics (upward acceleration/momentum from the jump and downward gravity acceleration) only while a character is in the jumping state. In that case, you'd need to employ different collision detection as well - you wouldn't want to collide with elements that are in the background of the jump. This can get complicated if you also want north/south control during the jump.

Alternatively, you can keep track of 3 dimensions for motion and calculate motion in 3D tiles, even while representing the world in 2 dimensions. This means jumping is just a regular case of motion. The disadvantage is more complex collision maps, since those would now be 3D. I only recommend this method if you want to have jumping collisions that are more complicated than what you can achieve with a 2D collision map.

Offline Kasumi

  • 0010
  • *
  • Posts: 275
  • Karma: +1/-0
    • View Profile

Re: Topdown Gravity

Reply #2 on: June 03, 2017, 05:32:58 pm
Mario Luigi Superstar Saga is a game like this with lots of gameplay involving gravity. It's basically a 3D gamestate with 2D graphics.

The Game Boy (Color) Zelda games, (and Minish Cap) allow jumping. For the Game Boy Zeldas, the height of the jump basically doesn't seem to matter. (There is some cuteness with raised switch blocks.) If you're grounded, you'll fall in pits and collide with enemies, if you're airborne you won't. All solid collision detection works the same.

I've programmed both types, I just used variables called Z, and Zspeed in addition to my X, Y, Xspeed and Yspeed. I do with Z and Zspeed what I would normally do to Y/Yspeed in a side scroller. To render the sprite, you just subtract Z from Y to get the right vertical position. Shadow rendering in the Game Boy way is just draw the shadow at X, Y.

If grounded and the jump button is pressed, set Zspeed to jump strength, set player to airborne.
While airborne, add gravity to Zspeed, add Zspeed to Z.
If Z is less than 0, set player to grounded, set Zspeed to 0, set Z to 0.

That'll get you to the Game Boy Zelda way. As eishiya mentioned, collision detection and representation of the collision map gets more complicated to do something like Mario Luigi Superstar Saga.
« Last Edit: June 03, 2017, 05:36:33 pm by Kasumi »
I make actual NES games. Thus, I'm the unofficial forum dealer of too much information about the NES