Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 efergan · Jul 29, 2012 at 10:56 PM · vectormagnitude

Working out a reversed magnitude of a vector without affecting the angle

Ok, this may be basic vector maths, so apologies. Then again, this may also be impossible. I hope to be informed.

Basically, I'm trying to add together a number of vectors (they represent the positions of enemies), to create one big vector (a threat vector I'm going to use in the AI) ... that bit would be simple, something like:

 foreach (GameObject enemy in enemies) {
 threatVector += (transform.position - enemy.transform.position)
 }

Apart from the issue that I want the smaller the magnitude (the closer the enemy) to create a larger vector.
As such I want to create some form of reversed magnitude, i.e. 50 - magnitude, but keep the overall angle the same.

Confused. Thanks for any pointers.

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
1

Answer by efergan · Jul 29, 2012 at 11:05 PM

I know I may be answering my own question here, but could I reduce the vector using something like threat.Normalize() and then apply that to a new magnitude, 50 - orignalMagnitude?

Comment
Add comment · Show 5 · 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 Bunny83 · Jul 29, 2012 at 11:22 PM 0
Share

Yes you can ;)

I've converted it into an actual answer ;)

The normalized vector will represent your direction information and the inversed magnitudes your new magnitude.

avatar image efergan · Jul 30, 2012 at 06:53 AM 0
Share

Thank you all as always. (Not sure if I should stick this here, may be classed as another question but...) How do I actually set a magnitude? Is it a matter of multiplying all the components, or a separate function of some type?

avatar image Piflik · Jul 30, 2012 at 06:57 AM 0
Share

Vector3.magnitude ...can be found in the script reference.

avatar image efergan · Jul 30, 2012 at 07:05 AM 0
Share

Read only though, right? Anyhow... I should test before I type, of course a normalised vector multiplies up..

avatar image Bunny83 · Jul 30, 2012 at 10:27 AM 0
Share

When the vector is normalized it has a length of 1.0f. You only need to multiply the vector with your desired length ;)

 threat.Normalize(); // now it has a lenght (magnitude) of 1.0f
 threat *= 5.0f;     // still the same direction but a magnitude of 5.0f;
avatar image
0

Answer by Piflik · Jul 29, 2012 at 11:21 PM

You could multiply each vector by 1/length². This would give you a hyperbolic dependence of the distance, the closer, the higher (infinity at zero, which means error, so you would have to test if the distance is zero ;)).

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 Bunny83 · Jul 29, 2012 at 11:31 PM 0
Share

Ehm, the multiplicative inverse doesn't really represent a linear relationship. Also length² makes it even worse ;)

It of course depends on what you need, but usually a linear relation is more predictable.

avatar image Piflik · Jul 29, 2012 at 11:33 PM 0
Share

Yeah, I meant hyperbolic...and while 1/length² is inverse square, length/length² equals 1/length, which is just inverse ;)

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

7 People are following this question.

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

Related Questions

Is it possible to clamp a Vector magnitude upwards (i.e. clamp to minLength)? 2 Answers

Does unity implement a way to convert an angle+magnitude representation of a vector to an x,y vector? 1 Answer

[MATH] Vectors, magnitudes, and bears; Oh My! -Solved 2 Answers

Vector3.forward question 1 Answer

Align an axis to a plane 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