- Home /
 
 
               Question by 
               EZCoding06 · Apr 11, 2020 at 04:39 PM · 
                c#cameramobileplayer movementfps controller  
              
 
              Move player based on camera direction (MOBILE JOYSTICK)
Hello, I am making a mobile 3d fps game. When I rotate the camera then move my player with a joystick, it moves my player based on the original position. How do I move based on the camera? Here is my code.
 public class PlayerMovement : MonoBehaviour
 {
     public Joystick joystick;
     public CharacterController controller;
     public float speed = 6f;
     // Update is called once per frame
     public void Update()
     {
         Vector3 direction = (joystick.Horizontal * Vector3.right + joystick.Vertical * Vector3.forward);
         controller.Move(direction * Time.deltaTime);
     }
 }
 
               ,Hi, I'm making a fps on mobile. I can't figure out how to move based on the camera direction. It only moves based on the original position. Here is my code.
public class PlayerMovement : MonoBehaviour { public Joystick joystick; public CharacterController controller; public float speed = 6f; // Update is called once per frame public void Update() { Vector3 direction = (joystick.Horizontal Vector3.right + joystick.Vertical Vector3.forward); controller.Move(direction * Time.deltaTime); } }
               Comment
              
 
               
              Your answer