Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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
0
Question by Ivan_Voloshin · Nov 29, 2021 at 05:31 PM · vector3normalizednormalize

Vector3.Normalize not working for particular input?

Hi,

Did I break unity?

Here is the code:

 Vector3 ax2 = new Vector3(0.3f, 1.0f, 0.0f);
 ax2.Normalize();
 Debug.Log(ax2);

Here is the log output: (0.3, 1.0, 0.0) //Not normalized!

And for this code:

 Vector3 ax2 = new Vector3(2.0f, 1.0f, 1.0f);
 ax2.Normalize();
 Debug.Log(ax2);

The output is: (0.8, 0.4, 0.4) // Normalized!

Same behaviour with ax2.normalized;

It drives me crazy. What am I missing?

I'm running: 2020.3.22f1 release

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

2 Replies

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

Answer by Bunny83 · Nov 29, 2021 at 05:43 PM

Try this instead:

         Vector3 ax2 = new Vector3(0.3f, 1.0f, 0.0f);
         Debug.Log("original length: " + ax2.magnitude);
         Debug.Log(".ToString: " + ax2);
         Debug.Log(".ToString(\"F1\"): " + ax2.ToString("F1"));
         Debug.Log(".ToString(\"F6\"): " + ax2.ToString("F6"));
         
         ax2.Normalize();
         
         Debug.Log("normalized length: " + ax2.magnitude);
         Debug.Log(".ToString: " + ax2);
         Debug.Log(".ToString(\"F1\"): " + ax2.ToString("F1"));
         Debug.Log(".ToString(\"F6\"): " + ax2.ToString("F6"));

You will get is this::

 original length: 1.044031
 
 .ToString: (0.3, 1.0, 0.0)
 .ToString("F1"): (0.3, 1.0, 0.0)
 .ToString("F6"): (0.300000, 1.000000, 0.000000)
 
 normalized length: 1
 
 .ToString: (0.3, 1.0, 0.0)
 .ToString("F1"): (0.3, 1.0, 0.0)
 .ToString("F6"): (0.287348, 0.957826, 0.000000)

Please have a close look at the results and make sure you interpret them correctly ^^

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
avatar image
0

Answer by Ivan_Voloshin · Nov 30, 2021 at 02:41 AM

Thanks! It was a string formating problem! The vector was normalized indeed. But due to only 1 decimal place in ToString() I couldn't see that. Interestingly is that if in debugger you highlight mouse cursor above the Vector3 object it will also show the result of ToString. Being a C++ programmer I'm not used to this and fell into the trap. Lesson learned.

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.

Follow this Question

Answers Answers and Comments

162 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Normalizing vector doesn't give a constant direction. 2 Answers

What is the difference between Normalize & Normalized 1 Answer

Jumping problem to do with /= magnitude changing the vector3 direction 1 Answer

Vector3.normalize not behaving as expected? 1 Answer

rigidbody.velocity.normalized application 1 Answer


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