Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

2D character controller - physics driven VS manual

Discussion in '2D' started by the_motionblur, Jul 20, 2015.

  1. the_motionblur

    the_motionblur

    Joined:
    Mar 4, 2008
    Posts:
    1,774
    So I'm trying to figure out (or better: learning by doing) whether a 2D sidescrolling character controller not driven mostly by physics is actually the better approach or if a similar result can be achieved by using Physics2D more easily.

    I've been starting to use my current free time to create a plattformer. The basis for my character controller is currently physics driven with the basis of @Mike Geig's training session for a 2D character controller.

    The thing is that I've hit a few obstacles in terms of character behaviour. It's the largest personal project I've created so far so of course there are going to be problems. Yet I was wondering if it's actually better for a 2D game to have a custom player controller that isn't driven by physics ... if it's worth it.
    For example: it's pretty difficult in physics to set a precise jumping heigt and speed for a character
    Also it's difficult to get the acceleration and stopping distance of a player "right" (with 'right' being a very subjective measurement to physics just feeling spongy and sometimes not in the right way responsive). There are other things - probably a lot I don't even know about yet.

    So I'm currently following the super awesome tutorial series by @SebastianLague - which is really great (and should also be added to the official library of Unity training, IMO). But it's obviously for me as someone with a focus on art rather than programming: it's just a little too much. In essence it's implementing a completely custom physics system for a player character.

    So I was wondering ... is it worth it?
    Can the same results and ease of use as with a custom 2D controller be achieved with physics?
    What do you guys/gals prefer to use and why?
    Should Unity integrate a 2D character controler like the one for 3D assets or is it better to build this thing from the ground up individually?
     
    gl33mer likes this.
  2. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    I've only built a few 2d games but I use a custom movement. This is personal preference as to me 2d games make me think of the old arcade games & my memory of them is every thing just happened, there was no acceleration or deceleration, jump height was always the same etc.

    I guess it depends on what feel you are going for overall with the game
     
  3. the_motionblur

    the_motionblur

    Joined:
    Mar 4, 2008
    Posts:
    1,774
    So what did you do with your custom character controller?
    Did you pretty much implement the complete physics replacement yourself?
     
  4. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Yeah, but as I'm still beginning I don't do complex physics yet, mainly move, jump, shoot, wind pushing the player,
    Moving on ice I used the physics add force stuff as that gives the effect of starting to move slower & then sliding to a stop.
     
  5. Zoltern

    Zoltern

    Joined:
    Jun 16, 2015
    Posts:
    14
    Hi,

    Yeah, i followed that same tutorial and ended up regreating it as you end up losing all the other stuff, like the effectors, might not work very well with joints and other elements. So far, for my 2D, i'm using a fully "compliant" physics controller :)
     
  6. the_motionblur

    the_motionblur

    Joined:
    Mar 4, 2008
    Posts:
    1,774
    So how did you setup your character controller to be able to walk slopes but also still be responsive in jumping and don't looking like a feather when falling to the ground again?
     
  7. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    I had artificial gravity applied to the rigid body when the character wasn't grounded, which I tweaked until it looked right when they fell.
     
  8. Zoltern

    Zoltern

    Joined:
    Jun 16, 2015
    Posts:
    14
    Slopes: Add force to the rigid body and have a circle collider at the bottom. He will do just fine :)
    Falling: Your scaling is wrong. I had the same error, it was due to everything being too big. Try to scale down everything or, in the worst case if you can't scale it down: increase both Gravity (before i scaled down, i had it up to 98 instead of 9.8 o_0) and the jump force.

    I would advise to scale it down, thou
     
  9. Zoltern

    Zoltern

    Joined:
    Jun 16, 2015
    Posts:
    14
    Oh, I had to use ForceMode2d.Impulse for the jump to work like i wanted (second parameter of the addForce method in rigidBody2D).