Search Unity

Classic 2D beat'em up setup

Discussion in 'Scripting' started by ypsilon, Mar 23, 2014.

  1. ypsilon

    ypsilon

    Joined:
    Feb 23, 2014
    Posts:
    5
    Although I've found several posts/questions on this topic, I still don't know what would be the best setup for a classic beat'em up. I started in 2D, but soon realized that it was not a good idea, since every classic beat'em up has depth. So now, although all the sprites are 2D, I'm using 3D. My camera is Ortographic, and points slightly down, to give that sense of beat'em up perspective. This is, I rotated it over the X axis.

    Now some questions:

    - For the characters, should I use CharacterController or RigidBody? I would like to take advantage of Unity's inherent physics capabilities, so I though that RigidBody would be the best idea... But I'm not sure about it.

    - In case of using a RigidBody, should I use a 3D or a 2D one?

    - What would be the best way to handle collisions? Should I use 2D or 3D colliders? I don't want my character to land on other characters when jumping and stuff like that.

    Thanks!

    PD: I'm new to Unity, but not to programming.
     
    Last edited: Mar 23, 2014
  2. SticksStones_

    SticksStones_

    Joined:
    Mar 23, 2014
    Posts:
    3
    I don't think you need any of that. A Classic 2D beat'em up is just about the only occasion when a 1D game engine will work perfectly - it's just the distance between the fighters. Jumping and crouching makes things a little harder, but only a little, essentially it's still a 1D world - it couldn't be easier.

    Moves can strike low, med, high and have different ranges and damage - I'd write the whole thing from scratch, using very little pre-built stuff. I might have a rigid body on my characters for visual effects only - to bounce particles off but not much else, you really don't need it.
    Keep the game engine really simple, then you can spend all your time on assets, animations and polish.
     
  3. diegzumillo

    diegzumillo

    Joined:
    Jul 26, 2010
    Posts:
    418
    That is one way of doing this, but the ground will probably have to be a textured plane instead of a sprite. No big deal though, it's what I'm doing on my 2d project. But you could achieve this using a complete 2d workflow, just like any 16 bit era game. They didn't have 3d camera and stuff like that, all was done creating the sprites with the desired angle, and moving things in the plane to simulate depth. But it's your call.

    It's totally up to you. You can still use the physics engine with your character controller but you'd have to code the interaction a bit yourself. For example, movement in X is not only dictated by input but by surrounding objects. Just like being punched may push the player back, a physics object can do the same.

    Rigidbody has the obvious advantage of having this interaction directly out of the package. It might be a little more difficult to implement though, character controllers that are rigidbody require a ton of tweaking to feel right, and there's a fair amount of caveats you need to be aware. For example, rigidbodies have to be controlled by forces instead of altering its position directly. Alternatively you can also change its velocity, but it's a completely different workflow and you might lose some of the advantage of using a RB.

    Everything I said above goes for both. At this point I don't know what would be the best approach. As tempting as it is to go with 2D, the current version of unity still carries a whole bag of bugs. Functions like ontriggerenter2D and similar are all full of bugs. On the other hand, these should be fixed any time soon, this is the first version with 2d features after all.

    It's hard to escape from colliders, whether you choose character controller (that has its own collider) or rigidbody (that requires colliders). A lot of things you could do with raycasts, like ground checking, though. But your concern has several ways to deal with. A character doesn't have to be made of a single gameobject with a single collider. You can have a whole hierarchy of gameobjects representing main body, attack volumes etc. Then you can configure the layer system of the physics engine to define what collides with what.
     
  4. ypsilon

    ypsilon

    Joined:
    Feb 23, 2014
    Posts:
    5
    Hey diegzumillo, thank you for your answer. At the end I'm using rigidbodies and I'm moving the character changing it's velocity (for the jumping too). I know that doing this directly shouldn't be done if you want to achieve a realistic feel, but anyway I don't want realistic behaviour in my game, so decided to do that.

    I'm using a 3D setup. That gave me a problem: since Unity uses the size of the objects to make the physics calculations, and my objects were actually "a plane" (plane sprites), they weren't being affected by gravity (they fell reaaally slowly). I solved this by creating an invisible cube and making the player a child of this cube. Now Unity treats them as a bigger object. The only problem is that the cube and the sprite don't seem to move together, and the cube just floats above.

    Now I'm getting into collisions. I'm using a 3d collider for the character, basically a thin cube. I will set more colliders in the fists and feet of the character in order to be able to detect them colliding with the enemies, although this will need more thinking.