- Home /
Move in the direction its facing C#
I have looked all over and found nothing that is working or I can take and use to move my player in the direction its facing. Can someone help me out?
 {
     [Header("Player Controll")]
     public float MoveSpeed;
     public float JumpForce;
     public float Gravity;
     private float VerticalVelocity;
     private CharacterController Controll;
     private Camera_Controll Cam;
     void Start()
     {
         Controll = GetComponent<CharacterController>();
         Cam = GetComponent<Camera_Controll>();
     }
     void Update()
     {
         if (Controll.isGrounded)
         {
             VerticalVelocity = -Gravity * Time.deltaTime;
             if (Input.GetKeyDown("space"))
             {
                 VerticalVelocity = JumpForce;
             }
         }
         else
         {
             VerticalVelocity -= Gravity * Time.deltaTime;
         }
         float MoveDirFacing = Input.GetAxis("Mouse X");
         if (Input.GetMouseButton(1))
         {
             transform.Rotate(new Vector3(0, MoveDirFacing * MoveSpeed * Time.deltaTime, 0));
         }
         Vector3 moveDir = new Vector3(0, VerticalVelocity, 0);
         moveDir.x = Input.GetAxis("Horizontal") * MoveSpeed;
         moveDir.y = VerticalVelocity;
         moveDir.z = Input.GetAxis("Vertical") * MoveSpeed;
         Controll.Move(moveDir * Time.deltaTime);
     }
 }
Answer by jni97 · Feb 09, 2017 at 09:03 PM
Hi, you can use Controll.Move(transform.TransformDirection(moveDir) * Time.deltaTime); transform.TransformDirection will transform your vector that it fits the direction of you character. 
Answer by MarshallN · Feb 09, 2017 at 09:52 PM
Look at transform.Forward, it returns a unit Vector3 in the direction a transform is facing.
Your answer
 
 
             Follow this Question
Related Questions
Problem CC and plane 0 Answers
Using Input.GetAxis on a 2 Player Game 2 Answers
Jaggie, uneven speed with basic movement script. 0 Answers
CharacterCollider.Move always goes up!?!?! 2 Answers
Make the player face his movement direction 10 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                