Hi,
I’m fiddling around a bit with the scripts from the 2D platformer. I found the PlatformerController script to be quite big for what i wanted to do (basically just learn about various components etc). And this is what i go so far.
var speed = 6.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
private var moveDirection = Vector3.zero;
private var rotationSmoothing = 0.1;
function FixedUpdate() {
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {
// We are grounded, so recalculate
// move direction directly from axes
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
}
Now i want to rotate my characterController in the direction that i’m moving in using a piece from the 2d platformer script. But when i add this in, my character starts spinning around like crazy.
if (moveDirection.sqrMagnitude > 0.01)
transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation (moveDirection), Time.deltaTime * rotationSmoothing);
Could someone explain to me exactly what happens in this script and where i go wrong? Or atleast point me in the direction where i can gain better understanding.
Thanks!