x


Interpolate rotation of character.

Hi, i'm working on a 2D platformer and everything is good(animation, axes...) Exept when my Guy doesn't accually turn back. So i added the Quaternion and the proper rotation but still, here it is:

class CharacterMove {

var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
var rotationSmoothing : float = 1.0;
var moveDirection : Vector3 = Vector3.zero;
}
var movement : CharacterMove;

function Update() {


    var controller : CharacterController = GetComponent(CharacterController);
    if (controller.isGrounded) {

        moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, 0);
        moveDirection = transform.TransformDirection(moveDirection);
        moveDirection *= movement.speed;

    if (movement.moveDirection.sqrMagnitude > 0.01)
    transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation (movement.moveDirection), Time.deltaTime * movement.rotationSmoothing);

        if(Input.GetButton("Jump")) {
            moveDirection.y = movement.jumpSpeed;
        }
    }

    moveDirection.y -= movement.gravity * Time.deltaTime;

    controller.Move(moveDirection * Time.deltaTime);
}

    @script RequireComponent (CharacterController)
more ▼

asked Oct 24, 2010 at 05:28 PM

La Frite Chaude gravatar image

La Frite Chaude
15 12 8 14

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3668
x758
x588
x186
x9

asked: Oct 24, 2010 at 05:28 PM

Seen: 1532 times

Last Updated: Oct 24, 2010 at 05:28 PM