playMaker

Author Topic: 2D Top Down "Platforming" (jumping and landing)  (Read 9473 times)

fishfood

  • Playmaker Newbie
  • *
  • Posts: 4
2D Top Down "Platforming" (jumping and landing)
« on: August 25, 2015, 08:58:55 PM »
Hi,

Just a brief intro, I've been making non commercial games for years, (though non consecutively), and have a few finished projects, so while I'm not totally new to the game creation process, I am new to Unity and can only use scripting languages, if that (C#? Not in this lifetime. I'm really more of an artist who's been forced to wear multiple hats). Having said that, I'm hoping Playmaker will allow me to start moving towards Unity development.

I've taken a few tutorials to get me familiar with the tools (both Playmaker and 2D Toolkit), but the funny (and maybe sad) thing is, I can't find one tutorial for any top down 2D games that aren't scrolling shooters, least of all one that has jumping. And I know this is possible because, well, to get to the point...

I'm looking to prototype a game similar to these:
https://www.youtube.com/watch?v=3uvM-vKVgGQ
https://www.youtube.com/watch?v=xGtgO-jX76A

As of now, all I can do in Unity via Playmaker is have you jump vertically on the Y axis on a horizontal scrolling game, where rigidbodied assets have collision at the very top of the object, and you could fall off the map. But with a game that scrolls vertically downward, I can't exactly have the character fall down the Y axis. I can translate the player object down the Y axis if I disable gravity, but it doesn't look like it's jumping. Plus, it needs to stop dead center in the middle of rocks, which are also sprites. If I have the rigidbody enabled, the player character just sits on top of the sprite as opposed to landing in the middle.

I'm looking to do this in the most effective/efficient way, so while I'm sure I could cheat in the animations by just having the character's jumping sprites increase upward on the Y axis, I can't see that being effective for longer jumps, and the farthest distance is jumping over 2 rocks and landing on the 3rd. Additionally, if you time your jump incorrectly and jump where there is no rock, you fall in the water, so there still has to be something there to detect a miss (and not just fall into a void). I'm thinking maybe an invisible object would go there, but I could be wrong.

As a final note, I also want to mention that this game will be endless until you miss or the big bad guy behind you catches up to you, so would it be better to have the character actually move downwards on the Y axis on a seemingly long playfield, or should the character not actually move down the Y axis at all, and everything else scrolls upward (of course with objects being destroyed at a specific coordinate)? If the latter is the case, the enemy will have to be scrolled upward too while still approaching, if that makes sense.


 
« Last Edit: August 25, 2015, 09:02:46 PM by fishfood »

sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
Re: 2D Top Down "Platforming" (jumping and landing)
« Reply #1 on: August 26, 2015, 10:48:58 AM »
Hi I have been dealing with this right now and it seems like the best way to handle this in unity is to make it in 3D but still using sprites etc with a top down camera.

The way I am currently doing it is in 2D but faking the Y on the sprite which has been a bit of a mission. It seems to be much easier in programs like GameMaker since they are built for 2D but I guess it is possible in Unity which is what I am trying to achieve.

I have the character game object with two children, the main sprite and its shadow. Sprite goes up and down with Y and if close enough to an object based on distance is when I trigger my events.
All my VR games use Steam VR Playmaker Toolkit: http://u3d.as/u20
And Oculus Touch Playmaker Toolkit: http://u3d.as/QT5


Follow me @sebasRez

fishfood

  • Playmaker Newbie
  • *
  • Posts: 4
Re: 2D Top Down "Platforming" (jumping and landing)
« Reply #2 on: August 26, 2015, 07:33:05 PM »
Yeah, it seems needlessly difficult all because Unity was first and foremost built for 3D with a 3D engine. If this was in Gamemaker, perhaps, or heck even Flash this prototype would probably be done already. But, my target is mobile and I need to use something that's not going to add a lot of strange overhead or be prone to the other little things Gamemaker tends to be known for.

I did think about top down 3D, but I worry that it could break the illusion. The aesthetic should really be 100 percent 2D, even down to effects (no particles or generated shadows. I'll make a black circle using pixel art that has a few shrinking frames for distance but nothing fancier). By habing the character jump on a 3D top down perspective, won't that make the sprite grow too?

sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
Re: 2D Top Down "Platforming" (jumping and landing)
« Reply #3 on: August 27, 2015, 09:05:31 AM »
Yes, it will. Thats the downside to making things look completely 2D in a 3D environment. Things will look smaller in a distance, and larger up close. Depending on your camera it won't be by much.

Like I said, my setup is done completely in 2D so I have to find a way to fake the gravity. If you want to see a script I am using (I haven't shared it because its not done yet. Could use more with shadows but it works great on making a character fake bounce.) You need to have your child sprite object be called sprite for it to work because the code will be looking for it to make bounce.

I want to add the shadow to grow and shrink based on distance and add a bounce so if you know anything about scripting we can probably work together on making 2D work in unity :D
All my VR games use Steam VR Playmaker Toolkit: http://u3d.as/u20
And Oculus Touch Playmaker Toolkit: http://u3d.as/QT5


Follow me @sebasRez

fishfood

  • Playmaker Newbie
  • *
  • Posts: 4
Re: 2D Top Down "Platforming" (jumping and landing)
« Reply #4 on: August 27, 2015, 08:23:54 PM »
Ugh. Lame. That hurts me more in the long run because now I wonder what else Unity can't really do well. I was going to build from the prototype to doing other top down games, not that those would've involved jumping (so I guess more Bomberman-like), but I mean, if it's going to do top down all wrong, maybe I'd be better off biting the bullet and accepting using an engine with some known porting issues if it means getting the game to be made the way I want it? ...that actually sounds insane.

I'm not licked yet, though. I'm at least going to make the current game with Unity. I can try your method, but I would need it explained a little more thoroughly. D: I'm really more of the guy you go to for art advice. As for your shadow, are you using the built in shadow or something drawn? Wouldn't a sprite based shadow just animate with your jump? Something like the shadow looks out for an event when the character jumps, and once the character does so, the shadow shrink/grow animation plays? I may be oversimplifying it, but then again I'm also think into terms of user created assets rather than built in stuff.

sebaslive

  • Hero Member
  • *****
  • Posts: 572
    • Frame Tale Studios
Re: 2D Top Down "Platforming" (jumping and landing)
« Reply #5 on: August 27, 2015, 10:33:12 PM »
So for the setup you would have an empty game object, lets say its the player. Then you create a new game object of your sprite and place that as a child of the player. Then you create another game object with your shadow sprite and add this game object as a child to the main player object.

So the player game object and its two children objects, player sprite and shadow sprite. That way when you move your player and it jumps, what is really moving up is the player sprite on y and since the shadow is staying with the main game object it will look like the character is jumping!

The script i added in my last post simulates the fake gravity that you will need to have it look like it is coming up and down.

This whole thing has been pretty challenging for me but luckily enough I know a bit to code actions if need be but if you are not as comfortable with coding yet, it may be best to use 3D first or try it out anyways
All my VR games use Steam VR Playmaker Toolkit: http://u3d.as/u20
And Oculus Touch Playmaker Toolkit: http://u3d.as/QT5


Follow me @sebasRez

Justin

  • Junior Playmaker
  • **
  • Posts: 58
Re: 2D Top Down "Platforming" (jumping and landing)
« Reply #6 on: August 30, 2015, 02:03:17 PM »
If I understand you correctly, you want to make an infinitely scrolling top down 2d game where you character appears to be moving upwards on the screen, and he is able to short jump, normal jump or long jump pits and obstacles. Such as, in the Kirby video…

For most infinite runner types of games I would move the environment and not the character. Unity has limited 3d space even though it is quite vast it is limited. So once you reach coordinate 1,000,000+ or whatever it actually is, the physics along with other things start misbehaving and become unpredictable. So you would have to reset the player’s position back to 0,0,0 or a space more stable ever so often. In my experience it’s much easier to move and spawn the background seamlessly.

As for your character since you only need him to idle, jump short, jump normal and jump long; I wouldn’t even mess with rigidbodies and physics to control him.  I would suggest using triggers/colliders/tags to handle just about everything. (I am also assuming your character jump input is coming from 3 different key presses or gestures. If that isn’t what your doing let me know.)

If the places that your character will be jumping to are evenly spaced like in the kirby game it shouldn’t be too hard to get working, if they are not evenly spaced there are other solutions that should only be a little more difficult to get working.
 
Character FSM – turn on player collider, Idle animation, jump short event, jump normal event, jump long event; when jumping play jump animation, turn off player collider (to make this easy, use an empty object parented to the player for the collider), move the background 1, 2, or 3 places (this will be the distance between the center of your obstacles/platforms/etc ) on the y axis depending on jump; turn on player collider, use global events here that correspond to the types of spaces the character will land on. These events will be fired from your collision manager and either end the game, add some other effect or loop back into the idle start state.

Obstacles/Platforms/Water/etc. – I would create custom tags for these correspondingly and give each it’s own collider or trigger. You can then use the collision event, or trigger event actions to effect what you want to have happen in your game when the character lands on them. I would create an FSM on an empty object that managed all the collisions by their tags. I would also parent these objects or their spawn points (depending on how you set your game up) to your level background that will be moving when the character jumps. Also remember to use activate and deactivate actions instead of destroy and create (as destroy and create will cause performance hiccups if your doing it all them time) for your level pieces, you will need to reset their position in queue after the player passes through them…

This is just going off the top of my head some of these things may need to be tweaked a little. If you decide to stick with unity and playmaker and use this approach let us know. I’m willing to help if you have any other questions or just need a more clear explanation.

fishfood

  • Playmaker Newbie
  • *
  • Posts: 4
Re: 2D Top Down "Platforming" (jumping and landing)
« Reply #7 on: August 30, 2015, 08:45:16 PM »
Sebaslive and Xensamurai: I'll give both of these a whirl when I can. I unfortunately didn't have much time this weekend and the entire upcoming week is going to be rather jammed with jobs and obligations, so I might not really get a chance to settle down until the end of the week, what with Labor Day approaching.

As for additional information, being that I want to turn this into a mobile game if it works, the only controls would be touching the screen to jump (or essentially a left mouse click). The distance of the jump is determined by the time between when the player "lands" and the next click. Immediate jumps are longer, and pausing after a landing gives shorter jump (essentially creating sort of a twitch based gameplay). A depleting meter that runs hot to cold should show this off, but I'll worry about the graphics for that later.

And as for objects, it's only lily pads. You either jump on one or you don't, and seeing as your farthest jump is 3 pads worth, I thought of seven combinations that I'd make prefabs out of where it's either all 3 pads below the character, one missing in various spaces or two missing. These should be randomly generated, but I'm thinking with some sort of odds that make the game less likely to produce the single pad prefabs the lower your score is. Conversely, higher scores are less likely to produce prefabs where all three are present.

And that's really it, aside from a constantly approaching object, a large fish or so, trying to catch you from behind, which means you can't sit around for too long. Additionally, its speed should increase with score or progress as well, and I'm thinking the player should too (that is, the speed at which the character moves from one pad to another increases, or maybe the speed that objects are shifted upwards anyway, sort of like the 2D Kirby example).


« Last Edit: August 30, 2015, 08:47:10 PM by fishfood »