x


Player Movement - Non Strafing Quaternion Method

Many games involve directional playermovement without strafing. Instead we see character models rotating to face the direction of the input and move in that direction. In this script I incorporate the simple Move script within character controller and I added additional code to rotate the character model towards the direction of input.

    void Update () 
    {

       CharacterController controller = GetComponent<CharacterController>();

       if (controller.isGrounded) { //If we're on the ground

       if(movementEnabled) //When we're allowed to move
         {
            moveDirection = new Vector3(Input.GetAxis("Left/Right"), 0, Input.GetAxis("Down/Up"));
            moveDirection = transform.TransformDirection(moveDirection);
            moveDirection *= skateSpeed;


 transform.rotation *= Quaternion.AngleAxis(new Vector3(Input.GetAxis("Left/Right"), 0, 0));

Currently the transform.rotation has the error " No overload for method AngleAxis' takes1' arguments". However, it is still unclear to me for how to use quaternion for this commonly used method of player movement.

Thanks for the help!

more ▼

asked Apr 09 '12 at 10:37 AM

SimonDenton gravatar image

SimonDenton
22 2 8 10

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

1 answer: sort voted first

I managed to find a script close enough to what I was aiming which did not require use of Quaternion. Thanks to VS48!

CharacterController controller = GetComponent<CharacterController>();

    if (controller.isGrounded) { //If we're on the ground

    if(movementEnabled) //When we're allowed to move
       {
    moveDirection = new Vector3(Input.GetAxis("Left/Right"), 0, Input.GetAxis("Down/Up"));

    moveDirection *= skateSpeed;        
       transform.forward = Vector3.Normalize(new Vector3(Input.GetAxis("Left/Right"), 0f, Input.GetAxis("Down/Up")));


       }
    }
more ▼

answered Apr 21 '12 at 11:52 AM

SimonDenton gravatar image

SimonDenton
22 2 8 10

(comments are locked)
10|3000 characters needed characters left
Your answer
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:

x4167
x2169
x1370
x955

asked: Apr 09 '12 at 10:37 AM

Seen: 442 times

Last Updated: Apr 21 '12 at 11:53 AM