I decided to ditch the character controller and go back to use a rigidbody.
the interactivity with other objects is a must for our game, so we better
embrace Unity’s built-in physics, instead of applying it manually
The problem is that the character starts acting very weird (rotating like crazy) when standing still. I read that Otee warns about Lookrotation with rigidbody, so I want to try another option. I can’t rotate a child for practical reasons (as mentioned as a solution in the thread).
So, my intention is to add torque to my character until it reached the right direction. But how can I calculate how much torque needs to be applied, and which direction?
We definately do recommend using rigidbody.freezeRotation and rotating through the transform interface.
If you are making a first person controller you should:
Use freezeRotation
Make sure you are using the Capsule collider. Make sure the capsule center is at the pivot point of the transform.
If you follow that, you can safely modify rotation through the transform interface with no problems.
The only case when using freezeRotation might be a problem is when the pivot point of the transform is very far off from the rigidbodies center of mass. This is seldomly the case.
Do you mean pushing other objects or being pushed by objects?
If it is only for pusing other objects. This is really easy to do with the character controller.
var pushForce = 300.0;
// Push all rigdibodies forward when running into them!
function OnControllerColliderHit (hit: ControllerColliderHit)
{
var body : Rigidbody = hit.collider.rigidbody;
// Only rigid bodies
if (body)
{
var normal = transform.TransformDirection(Vector3.forward);
body.AddForce(normal * pushForce);
}
}
Cool! I could even calculate the current char.controller velocity and apply a dynamic value to the rigidbodies.
However…its because of the interaction both ways: let’s say my character jumps on platforms with a spring attached. Or floating platforms in water. Thats so much easier with physics.
sqrMagnitude is the square length (length^2).
You often use square length for comparison instead of length to avoid the square root which is involved when calculating the length of a vector.
The mini game is going to be about ships attacking your base. You can blast them with your handcannon, but if you’re not fast enough, they’ll aim at your tower. The longer you remain on the tower, the better your score.
I hope I’ll be able to calculate how the cannonballs must be shot so that they will hit the tower from every direction though
And btw, the collision responds doesnt always return “true” when I touch other elements in the scene, as a result of this the char doesnt always jump when pressing space. Thats odd.