Search Unity

Rigidbody VS Character Controller

Discussion in 'Scripting' started by Metal Head, Oct 13, 2011.

  1. Metal Head

    Metal Head

    Joined:
    Aug 14, 2010
    Posts:
    411
    So I am finally ready to start a serious project. I'm currently working on concept and story and I'm nearly finnished. I aim to make a reallistic first person shooter so my question is:

    Which is better to use? The rigidbody or the character controller? What are their pros and cons? Which one would you suggest me?
     
  2. amit1532

    amit1532

    Joined:
    Jul 19, 2010
    Posts:
    305
    i suggest a Rigidbody.
    it takes less performence. and much more realistic, also support moving platforms.
    but you will need to know some physics and some more functions like how to know when you are grounded... because that feature is only in the Character Controller.
     
  3. Metal Head

    Metal Head

    Joined:
    Aug 14, 2010
    Posts:
    411
    I have developed a system for that actually:
    I add a sphere with a radius, smaller than the player's capsule. I make the sphere stick just a little bit outside from the bottom of the player's capsule collider. I then make it a trigger and make it ignore the player's layer.

    But if I am to slow down time for example:
    Because the rigidbody runs in the fixed update, the movement would look pretty bad. That's one of the minuses of the rigidbody.

    Another problem for me is that I never managed to make the movement of the player realistic with both methods. For example if I am to control the rigidbody's velocity directly, it would move pretty well, but pushing other rigidbodies...not going to be so reallistic. The player will be able to push them around as if they weight nothing. However, the rigidbody uses physics and I have realistic sliding down slopes etc. Something that I'll have to script myself with the character controller. And if I use force adding on a rigidbody, it would behave pretty good, but it will have trouble climbing stairs and it would slide like hell through the level.

    I'd like to hear more opinions. I'm definitely a fan of the rigidbody and I agree with you however.
     
  4. techtycho

    techtycho

    Joined:
    Sep 10, 2020
    Posts:
    4
    I would suggest the Rigidbody component, But here is the Pros and Cons of each one:

    Rigidbody_________________________Character Controller
    * Built in Gravity_____________________ * Handles steps
    * Built in Drag_______________________* Handles slopes
    * Interacts with Physics objects_________* Doesn't get stuck in walls
    _________________________________ * Easy to make snappy
    _________________________________ * Built in Ground Checking
    __________________________________ * In-air movement

    Rigidbody is missing some features like the Ground Checking, But I have a solution for this:

    Code (CSharp):
    1.  
    2.      void Start() {
    3.      if (Physics.Raycast(transform.position, Vector3.down, 1.1f))
    4.      {
    5.            //Code goes here
    6.      }
    7. }
    8.  
    This code for example will run the code in the if statement when the player is on the ground, Simply it sends a raycast, very similar to Controller.isGrounded.

    To move an object using Rigidbody, Just use the movePosition method.
     
    Last edited: Dec 16, 2020
  5. Deleted User

    Deleted User

    Guest

    Rigidbody players get stuck on walls because of friction. Add a physic material with no friction and it works. BTW you didn't mention that you can put any kind of collider on a Rigidbody in the Pro vs. Con list. Also, the basic capsule collider in a CharacterController feels really weird on ledges. :D
     
  6. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    A Rigidbody isn't "realistic" for a moving person. As I'm sure you've noticed, humans are not a fixed "rigid" shape.

    If you really want realistic movement for a person then it's actually a pretty complicated thing to do, which is likely to need some game-specific custom work. Most games go for unrealistic movement which feels good and then add an animation layer on top which tries to make it match up with the world. For example, "inverse kinematics" are often used to place feet on the ground after deciding what position the player should be in.

    When you say you want to make a "realistic first person shooter", what specific things do you mean by "realistic"?

    One example of a game which I think did "realistic" controls quite well is Grand Theft Auto V. However, note that players of fast paced FPSs often weren't a fan of its controls. That's because in a fast paced FPS if you press a direction the player goes in that direction nearly instantly. In GTA V when you press a direction the character starts moving their muscles to accelerate their legs appropriately to start walking in that direction.