I decided to not use the CharacterController since I want to have a better collision detectio(it’s a difference if a bullets hits the arm or the head ).
So, I’ve put capsule colliders to the arms and legs and have one major problem: How can I move the character now?
Disclaimer: You will almost definitely need a rigid body. Manual collision detection is only worth it in very special cases. I would suggest letting the Unity physics engine benefit you that way. But that also means you must use a method that involves Physics in your motor. That means no Transform Transform.Translate()
There are a number of ways based on the effect you want. For real tight controls I recommend directly modifying rigidbody.velocity
and rigidbody.angularVelocity
. The new example scene shipping with 3.4 uses that method to move the main character.
For other interesting and fun methods:
- Try Rigidbody.AddForce() and AddTorque(). Those probably won’t work well for characters, but could be useful for platforms and such. The problem is usually that it is hard to get a constant speed using these methods.
- Joints can create a very effective but loose control feel. The most important being the Configurable Joint. You can modify its motor properties through scripting to drive your character. I did this for a game where the characters moved somewhat like the people in Little Big Planet. They are physically controlled so the controls are definitely not tight enough for an FPS or action game, but it has a very charming feel to it.
- There is also Rigidbody.MovePosition(). That would work fine, but I think it leads to bizarre collisions so I generally don’t use it.
It is not use the charactercontroller, but to have a the rigidbody in you character.
And freeze the rigidbody X ad Z rotation.
function FixedUpdate()
{
var vector3Move = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
transform.Translate(vector3Move * moveSpeed * Time.deltaTime, Space.World);
if (this.rigidbody)
{
rigidbody.freezeRotation = true;
}
}