Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
21
Question by Ehren · Nov 02, 2009 at 08:21 PM · physicsrigidbodycollidercharactercontrollerkinematic

Guidelines for using rigidbody, collider, CharacterControllerScript, etc?

Understanding the physics engine and all the options for controlling game objects can be quite daunting for a Unity newbie. How do I know when to use a rigidbody (kinematic or non-kinematic), a collider, the CharacterControllerScript, or something else?

What are the basic guidelines for what to use, and how/when to use them?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
60
Best Answer Wiki

Answer by Ehren · Nov 03, 2009 at 11:22 PM

Overview

Here are some general rules-of-thumb.

  • Static scenery
    • Collider, No Rigidbody
  • Movable scenery/objects
    • Collider + Rigidbody (IsKinematic=false)
  • Characters
    • CharacterController (includes a Capsule Collider) + Custom control script
    • OR Collider + Custom control script (can cause issues if your character interacts with rigidbodies)
    • OR Collider + Rigidbody (IsKinematic=true) + Custom control script
    • OR Collider + Rigidbody (IsKinematic=false) + One or more Configurable Joints (which can be used to constrain the rigidbody's motion or rotation, if necessary) + Custom control script

Movement

When using CharacterController, movement is accomplished by calling the functions exposed by CharacterController. Interaction with other objects (platforms, crates, etc.) is accomplished by implementing the collision events exposed by CharacterController and applying forces to the objects the character collides with, or moving the character in response to the movement of the other objects.

When using a kinematic rigidbody, movement is accomplished by directly modifying your game object's Transform, or by calling rigidbody.MovePosition. (Note: the movement of kinematic rigidbodies should be done in FixedUpdate.)

When using a non-kinematic rigidbody, movement is typically accomplished by calling rigidbody.AddForce and rigidbody.AddTorque, or by setting the rigidbody.velocity and rigidbody.angularVelocity directly.

Resources

A good overview of the physics engine, rigidbodies, and colliders can be found in the Physics section of the Unity manual.

About CharacterController

According to the docs, the CharacterController component "is mainly used for third-person or first-person player control that does not make use of Rigidbody physics." In other words, the CharacterController is a handy component you can apply to a game object if you don't want it to be controlled by the physics engine, but you don't want to have to write your own custom controller code from scratch.

Why wouldn't you want your character controlled by the physics engine? Well, oftentimes a character's movement is not physically realistic. A character might run like a rocket-powered cheetah, change directions mid-air, etc.

CharacterController allows you to create this kind of unrealistic movement, but handles many of the basics for you -- things like walking up steps and keeping your character from walking through walls.

Why wouldn't you want to use CharacterController? If your character isn't a human-like entity walking on the ground, it may not be a good fit.

More info on CharacterController can be found here.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image shavais · Oct 23, 2014 at 03:20 PM 0
Share

Very nice post. Excellent overview and summation. Is it in the wiki yet?

avatar image cmonroy · Oct 30, 2014 at 02:22 PM 1
Share

DiamondTearz now only has some scented candles in the link you provided...

avatar image Blueseth · Nov 26, 2014 at 04:28 PM 0
Share

Thank you for the thorough answer. This helped me get a much better understanding of when to use each component.

avatar image
12

Answer by WarpZone · Jun 18, 2010 at 08:57 AM

Protip: A lot of the default scripts are wrong, for example the old Lerpz tutorial, the FPS tutorial, and the tropical island demo. If you use these scripts as-is and you have a good framerate, you'll notice heavy jittering.

The cause is almost always that the camera updates its position using Update(), but the physics simulation only updates on FixedUpdate(). To avoid jittering, ALL objects which use physics movement, plus the camera, should ONLY change their position in FixedUpdate(), never Update(). Non-physical movements and animations can feel free to update in Update(). The camera is especially sensitive to this, since even slight jittering will affect the whole screen.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ehren · Jun 21, 2010 at 06:54 PM 2
Share

Shouldn't cameras that follow other objects use LateUpdate?

avatar image Fattie · Dec 11, 2011 at 09:09 AM 0
Share

This really is a protip, kudos to WarpZone for mentioning this. Warp, I'm sure you agree that the situation is made even more touchy when you are using networking to move objects. You have to be particularly careful in your thinking about what is really done when. The issue came up in this question http://answers.unity3d.com/questions/190028/multiplayer-jitter-caused-by-camera.html which may help others passing here

avatar image
0

Answer by Phoera · Aug 18, 2015 at 09:13 PM

Though Warp's advice is commonly true, in my concrete situation i got rid of jittering by using FixedUpdate for character moving and Update for all the camera issues, so you should play with it to see if it fits your situation

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Character Controller Pushes Car With Wheel Colliders? 0 Answers

Preventing objects from intersecting with minimal physics 3 Answers

Character Controller - Got Hit and Flying Physic 0 Answers

How can i Prevent Kinematic object not to pass through another rigidbody object 1 Answer

Creating a SIMPLE car. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges