Rule of Thumb
Rigidbody: Used more on "objects", because "objects" are "dead", their movements are generally by the physical system. So for the Rigidbody movement, do not use translate (), to use a variety of "force", such as: Rigidbody Addforce () method, through the "force" to let it move. In addition, Rigidbody can be combined with navmeshobstacle, because the latter is also used in the "thing", but generally do not share with navmeshagent, because these two will control the movement of objects, so there will be race condition. If you want to use it, tick the is kinematic, so if the Rigidbody is Kinematic property is checked, then rigidbody can be used with any other component, such as Navmeshagent, Charactercontroller.
Collider: Defines the shape of an object, and our collision detection is based on this shape, random Collider is the basis of collision detection, almost all objects in unity need to Collider. Even if we use Charactercontroller generally will delete the original Collider, but Charactercontroller itself with a capsule Collider. Collider is divided into static collider and Dynamic collider, the former means no Rigidbody collider, the latter indicates Rigidbody collider,static The collider object is preferably a stationary object, do not change his transform position to make it move, which will not only cause a lot of performance damage to the physics engine, but also produce some unpredictable behavior. So if we want a collider object to move through our script (for example, through the translate () method) and not want to be controlled by the physics engine, then we need to give this collider a checkmark with the rigidbody of is kinematic. Because Rigidbody is kinematic to let this rigidbody not be controlled by the physics engine. Conclusion: In the game, for those objects that may move in the future, we not only add collider, but also add rigidbody, if you want to be controlled by the physical engine, do not tick rigidbody is kinematic, if you want not to be controlled by the physical engine, Hope that through their own code or animation to control, tick rigidbody is kinematic, and this property can be changed in the script at any time, so as to achieve "ragdoll effect", "ragdoll effect" similar to the effect of CS, Most of the time the motion of the object is controlled by script and animation, and if it encounters an explosion, the motion of the object can be taken over by the physical system, which is the most appropriate time to open the is kinematic.
Charactercontroller: Used in "Characters", because "role" is mostly "live" (such as: the protagonist in the game, NPC, etc.), their movements are either player control, or script control, so generally do not need to be controlled by the physical system, if controlled by the physical system, The game's operability has been reduced. The "character" controlled by the player must not be used with Rigidbody, Charactercontroller. If NPC does not want to use rigidbody, please tick is kinematic. After using the Charactercontroller, do not use translate () to move the object, to use its own move () method to move the object. Otherwise there will be some "weird" problems.
Charactercontroller does not affect any "force", nor does it exert "force" on the object, even if that object is rigidbody.
Rigidbody will respond to the "force", if an object is added to the Rigidbody, the first will be directly to the "Gravity" response, if coupled with collider, will be a response to other "forces". At the same time, if you use translate () to move the rigidbody, it will automatically exert a "force" on the other rigidbody when it collides.
The IS trigger in collider has a priority higher than rigidbody (regardless of whether the collider and rigidbody labeled is trigger are on the same gameobject). Because Rigidbody is a physical simulation based on Collider, Collider is the basis of rigidbody, so if this collider is trigger, because trigger just by calling ontrigger* () function to respond to a collision, without responding to any substantial collisions (so-called physical collisions, which can be observed, such as motion after a collision, stopping an object from passing through, etc.). So even if the rigidbody is in, it does not work (the oncollision* () function will not be called, nor will it produce physical motion, nor will it prevent the object from passing through, anyway, no visible collision effect.
Similarly, the collider is trigger priority is also higher than Charactercontroller, but Collider and Charactercontroller are generally not put together, so this refers to the other object on the collider is Trigger.
Charactercontroller (do not add collider,charactercontroller with their own capsule Collider. And move the object using the Move () method)
Use Charactercontroller to collide with another object, if the object being collided with collider, and is trigger not checked, then whether the object is Rigidbody,charactercontroller will be the object "Block" down, and only trigger his own oncontrollercolliderhit () This callback function (that is, if the object being collided or its own ontrigger* (), oncollision* () This function, will not be triggered).
So if we want to implement a charactercontroller push the box game, then first this box must be rigidbody, and Collider is not Trigger, and this "thrust" It needs to be "emitted" in Charactercontroller's Oncontrollercolliderhit () function.
If the object collider by the collision is checked by the is trigger method, then because the IS trigger just treats collider as a "trigger" and does not respond to the actual collision (so-called physical collisions, which are observable collisions, such as motion after a collision, After the collision prevents the object from passing through, etc.), so the Charactercontroller will pass through the colliding object, and Oncontrollercolliderhit () This callback will not work, instead the ontrigger* () function of both sides will be called.
Rigidbody (if kinematic is checked, the rigidbody is not controlled by the physical engine)
Once an object is added Rigidbody, it can be immediately affected by the "Gravity", if coupled with collider, then can be affected by other "force", because collider is trigger priority higher, so if Collider is Trigger (whether this is Trigger Collider and Rigidbody on an object, as long as the collision between the two have appeared is Trigger), then this rigidbody will not have a substantial collision (so-called real collision, is a collision that can be observed, such as a motion after a collision, a collision that prevents an object from passing through, etc.). and ontrigger* () is called instead of oncollision* ().
Supplementary instructions on the invocation of the oncollision* () callback for Rigidbody (from: https://docs.unity3d.com/Manual/CollidersOverview.html):
With normal, non-trigger collisions, there are an additional detail, in least one of the objects involved must have a n On-kinematic rigidbody (ie, is kinematic must be switched off). If both objects is kinematic rigidbodies then oncollisionenter, etc, won't is called. With trigger collisions, this restriction doesn ' t apply and so both kinematic and non-kinematic rigidbodies would prompt a Call to Ontriggerenter when they enter a trigger collider.
Rigidbody:oncollisionenter (Collision c), Oncollisionstay (Collision c), Oncollisionexit (collision c)
Collider is Trigger:ontriggerenter (Collider c), Ontriggerstay (Collider c), Ontriggerexit (Collider c)
Charactercontroller:oncontrollercolliderhit (Controllercolliderhit c)
A general condition (not a requirement, as there is an exception, as explained later) that the collision (which can see the effect of the collision or the collision of an invisible effect like the collider of the IS Trigger) has a collider on both sides of the collision (whether or not it is Trigger), And at least one of them has rigidbody or charactercontroller. This time the collision is generated and the corresponding callback function is called. If more than one function can be called, look at the following precedence.
Highest priority: The collider involved in a collision with IS trigger will only invoke the ontrigger* () function on both sides and will not have a physical collision (so-called physical collisions, which can be observed collisions, such as motion after a collision, stopping an object from passing through, etc.).
Sub-high priority: a collision with charactercontroller participation and no is trigger will only call Charactercontroller (if the collision is also Charactercontroller, Then his oncontrollercolliderhit () will also be called) The Oncontrollercolliderhit () function. and will produce Charactercontroller by the object "file" down the effect, but otherwise there is no other physical effects.
Lowest priority: A collision with rigidbody participation, and no collider of Charactercontroller and is trigger, invokes the oncollision* () callback on both sides of the collision and simulates the physical motion after the collision by the physical system.
Supplementary instructions on the invocation of the oncollision* () callback for Rigidbody (from: https://docs.unity3d.com/Manual/CollidersOverview.html):
With normal, non-trigger collisions, there are an additional detail, in least one of the objects involved must have a n On-kinematic rigidbody (ie, is kinematic must be switched off). If both objects is kinematic rigidbodies then oncollisionenter, etc, won't is called. With trigger collisions, this restriction doesn ' t apply and so both kinematic and non-kinematic rigidbodies would prompt a Call to Ontriggerenter when they enter a trigger collider.
Why Collider is trigger has the highest priority. Because Collider is the foundation of all collisions.
Exception: If a moving object a (by changing the transform to make it move) and the stationary object B collide, a only collider, and is not Trigger,b is rigidbody, and Collider is not Trigger, Then any callback function is not triggered, and no physical simulation of the collision effect, a will pass through B. But if both A and B are stationary, and they start "next to each other", then this time it will collide again, because there is no is Trigger, so the Oncollisionenter () is called by both sides.
This exception in official documentation is known as fail to sleep:
The second paragraph in https://docs.unity3d.com/Manual/RigidbodiesOverview.html about sleeping.
The static collider is mentioned in the official documentation, the so-called Static Collider, which are those that are not used with Rigidbody Collider (conversely, those rigidbody used with collider are called dynamic Collider). These collider are generally used on stationary objects, and do not attempt to directly change their transform position (do not use the translate () method or assign a value directly to position) because this can have a significant performance impact on the physical engine. (See also: https://docs.unity3d.com/Manual/CollidersOverview.html). Charactercontroller There is no extra collider, and Navmeshagent's movement is controlled by the navigation system, and it is not the case that we say.
Expand reading (Very important):
Https://docs.unity3d.com/Manual/CollidersOverview.html