• 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 /
  • Help Room /
avatar image
0
Question by Tronline · Dec 28, 2016 at 02:48 PM · c#movementdiagonal

Character Diagonal Movement Issue

I've made a movement script + jumping but it seems like when I move diagonally (W + D/A) or (S + D/A) my character moves twice as fast as normal. I get it's because in the script I've done:

 moveDirection *= speed;

So it basically multiplies the moveDirection by speed, but when I press 2 keys like W and D I t$$anonymous$$nk it kinda multiplies both of the keys or the directions so it equals to twice as much as normal. How do I fix t$$anonymous$$s? Or maybe I'm just seeing t$$anonymous$$ngs and I'm actually moving normally? Thanks in advance :P

Comment
Add comment · Show 1
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 Tronline · Dec 28, 2016 at 02:42 PM 0
Share

3 Replies

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

Answer by AlwaysSunny · Dec 28, 2016 at 02:47 PM

You should normalize the input vector. Like so...

 float h = Input.GetAxis("Horizontal");
 float v = Input.GetAxis("Vertical");
 Vector3 inputVector = new Vector2( h, 0, v );
 inputVector.Normalize();

Then multiply it by your desired speed and use that to move the character.
T$$anonymous$$s will correct the issue.

T$$anonymous$$nk of it like t$$anonymous$$s: Without normalization, the input vector fits into a square. The corners of a square are further from the center than the middle of the edges are. Normalizing "chops off" the excess, so the final input vector fits into a circle, making the vector a uniform length no matter what direction it's pointing.

Best,

Comment
Add comment · Show 4 · 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 UnityCoach · Dec 28, 2016 at 06:51 PM 3
Share
avatar image AlwaysSunny UnityCoach · Dec 28, 2016 at 09:59 PM 0
Share
avatar image UnityCoach AlwaysSunny · Dec 28, 2016 at 10:15 PM 0
Share
Show more comments
avatar image
0

Answer by Tronline · Dec 28, 2016 at 02:57 PM

@AlwaysSunny Oh ok! I get it now, thanks!

Comment
Add comment · Show 2 · 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 AlwaysSunny · Dec 31, 2016 at 05:50 PM 0
Share
avatar image Tronline · Dec 31, 2016 at 06:29 PM 0
Share
avatar image
0

Answer by Dusty777 · May 18, 2018 at 05:52 AM

Also discussed here https://answers.unity.com/questions/639075/using-move-the-enemy-moves-faster-at-a-diagonal.html

Comment
Add comment · 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

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

How do I get diagonal 3d movement? 1 Answer

How To Move My Player With Sin And Cos Functions 1 Answer

How can I remove movement or camera rotation in one direction with a trigger 0 Answers

How to make an object go the direction it is facing? (Im new) 0 Answers

How to insert and offset on movement in the direction of he object is facing? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges