Search Unity

Move character in direction of camera

Discussion in 'Scripting' started by Corva-Nocta, Nov 26, 2015.

  1. Corva-Nocta

    Corva-Nocta

    Joined:
    Feb 7, 2013
    Posts:
    801
    Code (csharp):
    1. cameraDirection = cameraPlayer.transform.forward;
    2.      
    3. currentMovement = new Vector3(0, currentMovement.y, Input.GetAxis("Vertical") * moveSpeed);
    I'm trying so hard to find a line of code that needs to go between these 2 lines that will change the rotation of the player to the direction of the camera. To be clear I don't want the player constantly rotate to the direction of the camera, but only when I move forward does the player rotate to the direction of the camera.

    I know I'm so close but I just can't find the right way to do it. Any help at all would be great!
     
    Last edited: Nov 26, 2015
  2. doniv

    doniv

    Joined:
    Oct 4, 2012
    Posts:
    2
    Hi ,
    Try this
    Code (CSharp):
    1. if (Input.GetAxis ("Vertical") > 0)
    2.             Player.transform.forward = cameraDirection;