title: Make player move forward,right,left and backwards based on camera angle
body: <p>So far I have a player who moved forward left right and backwards, however how I have it set up it's forward as in forward on the grid, not forward where my player is looking. I have the camera set as FPS, with it following the player around. Now I want to have the player be able to look with my MouseLook script (works already) but based on that I want forward to be wherever the player is looking, not the primitive version I have. I'll post code below to let you know what I am talking about, ANY help is appreciated. </p>
  
  <p>Player Script (movement)</p>
  
  <pre><code>    void Update () {
  
      if(Input.GetKey (moveU))
      {
          SetTransformZ((transform.position.z) + playerSpeed);
  
      }
  
      if(Input.GetKey (moveD))
      {
          SetTransformZ((transform.position.z) - playerSpeed);
  
      }
  
      if(Input.GetKey (moveL))
      {
          SetTransformX((transform.position.x) - playerSpeed);
      }
  
      if(Input.GetKey (moveR))
      {
          SetTransformX((transform.position.x) + playerSpeed);
      }
  
      else
      {
          rigidbody.angularVelocity = Vector3.zero;
  
      }
  
  
  }
  
  void SetTransformX(float n)
  {
      transform.position = new Vector3(n, transform.position.y, transform.position.z);
  }
  
  void SetTransformZ(float n)
  {
      transform.position = new Vector3(transform.position.x, transform.position.y, n);
  }
  </code></pre>
  
  <p>MouseLook script (attached to Main Camera in Unity, this works witht he player so it goes whereever my mouse is looking, but the movement is off since my code to move is very primitive)</p>
  
  <pre><code>[AddComponentMenu("Camera-Control/Mouse Look")]
  
  public class MouseLook : MonoBehaviour {
  
  public enum RotationAxes { 
      MouseXAndY = 0, 
      MouseX = 1, 
      MouseY = 2 }
  
  public RotationAxes axes = RotationAxes.MouseXAndY;
  public float sensitivityX = 15F;
  public float sensitivityY = 15F;
  public float minimumX = -360F;
  public float maximumX = 360F;
  public float minimumY = -60F;
  public float maximumY = 60F;
  float rotationY = 0F;
  
  void Update ()      
  {
      if (axes == RotationAxes.MouseXAndY)
      {
          float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
          rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
          rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
          transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
      }
  
      else if (axes == RotationAxes.MouseX)
      {
          transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
      }
  
      else
      {
          rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
          rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
          transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
      }
  }
  
  
  
  void Start ()
  {
      //if(!networkView.isMine)
      //enabled = false;
  
      // Make the rigid body not change rotation
      //if (rigidbody)
      //rigidbody.freezeRotation = true;
  
  }
  </code></pre>