Home > OS >  Unity Charactercontroller component Question
Unity Charactercontroller component Question

Time:12-15

I am implementing a player in Unity. The movement of the player is implemented using the character controller. Then, I tried to give a Knock-Back effect, but it is not as effective as using the Rigidbody addForce() function. Is there a way to use a character controller and give an effect like the addForce() function?

I want to implement AddForce() with Character Controller.

CodePudding user response:

One option that is commonly used for rag doll like effects is to temporarily disable the character controller and enable the rigid body. It allows physics to temporarily control the character (and removes the ability of the player to control it). Then, after a set time the character control is re-enabled to regain control.

CodePudding user response:

Welcome to Stackoverflow!

If you desire an effect that can be achieved via a Rigidbody component, it makes no sense to use the Character Controller component, since it is explicitly made for use-cases where you don't want Rigidbody behavior. To quote the docs for Character Controller :

The Character Controller is mainly used for third-person or first-person player control that does not make use of Rigidbody physics.

Forthermore, it also illustrates why and when a Character Controller component might be useful:

The traditional Doom-style first person controls are not physically realistic. The character runs 90 miles per hour, comes to a halt immediately and turns on a dime. Because it is so unrealistic, use of Rigidbodies and physics to create this behavior is impractical and will feel wrong. The solution is the specialized Character Controller.

For those reasons, if you actually want Rigidbody behavior, your best option will be to give up on the Character Controller and implement the player behavior with Rigidbodies yourself.

  • Related