title: Player Movement Relative to Camera Direction C#
body: <p>I am fairly new to making games in unity and I am trying to get my player to move in a direction relative to the camera position. I have no idea how to do this, below is my code, would someone be able to help me with this?</p>
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class PlayerMovement : MonoBehaviour
  {
      // Start is called before the first frame update
  
  
      public Rigidbody rb;
      public Transform cam;
  
      public float movementSpeed = 6.0f;      //speed the player moves at
      public float jumpHeight = 200.0f;       //height of the jump
      public float timeBetweenJumps = 1.0f;   //delay between each jump so the player can't jump again before reaching the ground
      private float timestamp;
  
      public Vector3 movement;
   
      void Start()
      {
          rb = this.GetComponent&lt;Rigidbody&gt;();
      }
  
  
      void Update()
      {
        
          movement = new Vector3(Input.GetAxis(&quot;Horizontal&quot;), 0f, Input.GetAxis(&quot;Vertical&quot;));     
          transform.LookAt(transform.position + new Vector3(movement.x, 0f, movement.z));         // makes the player always face in the direction of movement
  
          if (Time.time &gt;= timestamp &amp;&amp; (Input.GetKeyDown(&quot;space&quot;)))
          {
              GetComponent&lt;Rigidbody&gt;().velocity = Vector3.up * jumpHeight;                       // multiplies the players Y position by the jumpHeight variable which causes the player to jump in-game
              timestamp = Time.time + timeBetweenJumps;
  
          }
  
      }
      
  
      void FixedUpdate()
      {
          moveCharacter(movement);    
  
      }
  
      void moveCharacter(Vector3 direction)
      {
          rb.MovePosition(transform.position + (direction * movementSpeed * Time.deltaTime));     //moves the rigidbody (player) 
          
      }
  }
  
  </code></pre>