Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Cheapest/best character controller for a 2D top down RPG?

Discussion in '2D' started by TwiiK, Jan 26, 2015.

  1. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    Question is in the title.

    I'm currently making a top down 2D RPG and I'm using rigidbody2D's with circle colliders for my characters. I'm moving them with MovePosition in FixedUpdate(). But yesterday I did a quick test with about 40 characters moving at the same time and Unity slowed to a crawl. I've easily been able to do the same thing with close to 200 characters in one of my 3d games.

    Obviously there could be other factors leading to the slowness (I will investigate later today), but I just wanted to ask if there were better ways of making 2D character controllers currently available as 2D physics are causing a few other headaches for me as well.

    My rigidbody2D's are not set to kinematic. Not sure if that will increase performance or not. After testing yesterday I realized I may have to do that because I don't know how to create friction in my 2D game using 2D physics and the characters kept pushing each other around. 2D physics do not allow for gravity along the z-axis. I'm almost starting to wonder if 3D physics are the way to go for a top down 2D game?

    2D colliders lead to other problems as well. For instance I can't raycast down along the z-axis from the mouse pointer and check what object is under the mouse pointer like I would be able to if I were using 3D colliders.
     
  2. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    Heh, 3D physics was a no go. Way too much of a hassle. And 3D gravity on the z-axis in a 2D game looked completely unnatural as well which was one of the things I thought I would get for free with 3D physics.

    I will stick with 2D physics and fake friction, gravity and whatever else I have to.

    As for my performance problem it was a stupid issue. I viewed both the scene view and game view at the same time inside the editor. :p I docked the profiler where I normally had the scene view and my performance skyrocketed, lol.

    Guess I will stick with rigidbody2D's for now.
     
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    40 shouldn't even be slow on mobile if I'm honest. You benchmarking the problem being actually physics?
     
  4. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    Yeah, like I said it was the scene view. Having both the scene view and the game view visible at the same time reduced my performance massively. I can have close to a thousand characters on screen at once now, but if 80-100 of them start chasing me and they begin colliding with each other the physics start eating up all of of my game's performance and my frame rate tanks. But I'll figure that out when I get to it. I doubt I'll have that many enemies in action at once, and some of them may not even collide with each other.

    But in conclusion having the scene view visible when playing in the editor will ruin your performance and that was problem originally. :p
     
    theANMATOR2b likes this.
  5. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yes but that's not a benchmark of the physics. It won't calculate physics twice for scene view and game view.