• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by SimonDiamond · Apr 04, 2013 at 10:53 PM · movementcharactermovingforwardsideways

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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();
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SimonDiamond · Apr 05, 2013 at 06:48 PM 0
Share

Ahh of course. Thank you!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why won't Character Controller Move Forward while in the Air? 2 Answers

Enemy moving sideways 1 Answer

Simple Character Movement 1 Answer

Having trouble moving character backwards... 1 Answer

Mixamo Character Movement 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges