Search Unity

Can anyone tell me why my character doesn't rotate

Discussion in 'Scripting' started by fatmario565, Jul 25, 2014.

  1. fatmario565

    fatmario565

    Joined:
    Feb 26, 2014
    Posts:
    4
    Can anyone tell me why my character won't rotate?

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class NewBehaviourScript : MonoBehaviour {
    5.  
    6.     public float movemetspeed = 5.0f;
    7.     public float mousesensitivity = 5.0f;
    8.     public float updwnrange = 80.0f;
    9.  
    10.     // Use this for initialization
    11.     void Start () {
    12.    
    13.     }
    14.    
    15.     // Update is called once per frame
    16.     void Update () {
    17.         //rotation
    18.  
    19.         float rotX = Input.GetAxis ("Mouse X");
    20.  
    21.         transform.Rotate (0, rotX, 0);
    22.  
    23.         float rotupdwn = Input.GetAxis ("Mouse Y") * mousesensitivity;
    24.  
    25.         float currentupdwn = Camera.main.transform.rotation.eulerAngles.x;
    26.         float desiredupdwn = currentupdwn - rotupdwn;
    27.  
    28.         Camera.main.transform.rotation = Quaternion.Euler (desiredupdwn, 0, 0);
    29.  
    30.         //movement
    31.         float forwardspeed = Input.GetAxis ("Vertical") * movemetspeed;
    32.         float sidespeed = Input.GetAxis ("Horizontal") * movemetspeed;
    33.  
    34.         Vector3 speed = new Vector3 (sidespeed, 0, forwardspeed);
    35.  
    36.         speed = transform.rotation * speed;
    37.  
    38.         CharacterController cc = GetComponent<CharacterController>();
    39.  
    40.         cc.SimpleMove (speed);
    41.     }
    42. }//
    43.