Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 RemDust · May 15, 2017 at 04:44 PM · directionvectornormalize

"normalize" a vector but conserve the "- sign"

Hi there !

I understand how normalize work but I'd like to know if there is a way to normalize the "magnitude" and NOT the direction/sens

I mean if my vector2is x=-3.4 and y=4, I'm looking for a method that gives me Vector2(-1,1)

Thanks for you help ! :)

Comment
Add comment · Show 2
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 leech54 · May 15, 2017 at 05:02 PM 0
Share

I am confused at what you are trying to do.

If you give the Vector2(-3.4,4.0) and normalize it the new vector2 should be Vector2(-0.64764842,0.761939318) not Vector2(-1,1)

Normalize keeps the magnitude of the new Vector2 to 1, but preserves the direction.

avatar image Bunny83 · May 15, 2017 at 06:50 PM 0
Share

What you describe here is not "normalizing". A normalized vector has an overall length / magnitude of 1.0. The vector (-1, 1) is not normalized. It has a length of "sqrt(2)" (about 1.41421)

Your original vector (-3.4, 4) has a length of about 5.248. When you actually normalize the vector the result would be approximately (-0.6476, 0.76194). This vector is normalized (has a length of 1.0 and does still preserve the direction)

I think you should be more clear about what you want to do.

Just for reference, this is how normalizing works:

 public static Vector2 Normalize(Vector3 aVec)
 {
     float len = $$anonymous$$athf.Sqrt(aVec.x*aVec.x + aVec.y*aVec.y);
     return new Vector2(aVec.x / len, aVec.y / len);
 }

So when you have a given vector "v" those lines do exactly the same:

 v = Normalize(v);
 
 v = v.normalized;

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by leech54 · May 18, 2017 at 11:04 AM

I am confused at what you are trying to do.

If you give the Vector2(-3.4,4.0) and normalize it the new vector2 should be Vector2(-0.64764842,0.761939318) not Vector2(-1,1)

Normalize keeps the magnitude of the new Vector2 to 1, but preserves the direction.

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
1

Answer by NoBrainer-David · May 15, 2017 at 06:13 PM

You probably want to use the Mathf.Sign function. Like so;

Vector2 myVector = Vector2(-2.0f, 1.3f); // some value

 myVector.x = Mathf.Sign(myVector.x);
 myVector.y = Mathf.Sign(myVector.y);
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

69 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

Related Questions

[2D] Angle to Vector conversion 1 Answer

Move point in the direction of another 1 Answer

Need to know euler angles of Vector3 direction relative to other Vector3 direction 1 Answer

How should I rotate a 2D unit vector by X degrees? 1 Answer

Vector direction after collision 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