- Home /
 
Moving character....northwest...?
Because of my lack of english knowledge i don't know how to easily describe what i want better than to say: How do i move my character "Nortwest, Northeast, SouthWest and Southeast with Transform.Translate?
To make things clear my character is currently moving relative to the camera so i'm all good there, but i want to be able to move the character "Sideways-Forward" by pressing "W" and "A" at the same time. When i do it now my character either goes forward or sideways when i want it to go...well..."Northwest"...if that is the proper way to put it.
Here's my current movementscript...
         if (Input.GetKey(KeyCode.W))
         {
             Direction = Vector3.forward;
         }
         if (Input.GetKey(KeyCode.S))
         {
             Direction = Vector3.back;
         }
         if (Input.GetKey(KeyCode.A))
         {
             Direction = Vector3.left;    
         }
         if (Input.GetKey(KeyCode.D))
         {
             Direction = Vector3.right;    
         }
         Direction.Normalize();
         transform.Translate(Direction * MovementSpeed * Time.deltaTime);
 
               Sorry if i'm being unclear. Thanks for reading!
Answer by Statement · Apr 04, 2013 at 11:01 PM
Just add the directions together:
 Direction = Vector3.zero;
 if (Input.GetKey(KeyCode.W)) Direction += Vector3.forward;
 if (Input.GetKey(KeyCode.S)) Direction += Vector3.back;
 if (Input.GetKey(KeyCode.A)) Direction += Vector3.left;
 if (Input.GetKey(KeyCode.D)) Direction += Vector3.right;
 
 // If you don't want up/left to give speed boost etc:
 // Direction.Normalize();
 
              Your answer
 
             Follow this Question
Related Questions
Simple Character Movement 1 Answer
Having trouble moving character backwards... 1 Answer
Mixamo Character Movement 0 Answers
Why won't Character Controller Move Forward while in the Air? 2 Answers
Enemy moving sideways 1 Answer