Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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
1
Question by JackieTilley92 · Feb 10, 2016 at 11:21 AM · 2dvector3beginnermath

Extending a vector?

Hi,

My problem is more of a basic vector maths problem then a scripting problem.

I want to be able to make a vector longer. I have a vector from the origin of one circle to the point of origin on another circle and I want to be able to use this vector to find an Extended vector represented in green of a different magnitude.

Does anyone have any ideas of how to do this?

alt text

Thank you in advance.

vector.png (5.9 kB)
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

4 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by mikelortega · Feb 10, 2016 at 11:24 AM

Multiply your vector by a scalar. Check this.

 Vector3 extended_vector =  your_vector * (float);

To extend it to a known magnitude, you can first normalize your original vector:

 your_vector.Normalize();
 Vector3 extended_vector =  your_vector * the_magnitude_you_want;
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
2

Answer by Guhanesh · Feb 10, 2016 at 12:09 PM

//Let the bigger circle centre position be A and smaller circle position be B and Extended

// position be C

public float float ExtenDis=5;

Vector3 normVector = (A.position-B.position).normalized;

B.position=B.position*normVector*ExtenDis;

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 mikelortega · Feb 10, 2016 at 02:39 PM 1
Share

I guess you mean:

 Vector3 normVector = (B.position-A.position).normalized;
 C.position = A.position + normVector*ExtenDis;
avatar image
0

Answer by 5c4r3cr0w · Mar 12, 2016 at 02:43 PM

Okay lets say bigger circle has c1 center and smaller circle has center c2. So the direction will be c2 - c1 . Now you need to normalize vector so the magnitude becomes 1 and then multiply it with any digit so it can be extended to your desired position.

Here is some code :

 public Transform c1, c2, res;
 public float unit;
 Vector3 result;

 void Start ()
 {
     result = c2.position - c1.position;
     res.position = result.normalized;
 }

 void Update ()
 {
     result = res.position * unit;
     Debug.DrawRay (c1.position, result);
 }



Tweak the value of unit so you get desired results.

Hope this helps

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 toddisarockstar · Mar 12, 2016 at 05:10 PM

you can simply subtract two vector threes to get direction. then simply add it to go past your second point.

 var heading:Vector3;
  var howfarpas:float;
                     howfarpast=.5;
     
     var yournewspot:Vector3;
     
     heading = target.position - player.position;
     
     heading=heading*howfarpast;
     
     yournewspot = target.position+heading;
 
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

7 People are following this question.

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

Related Questions

how i can write a text from another code ? 2 Answers

Staring a 2D game 2 Answers

Unable to fully rotate GameObject on tap 2 Answers

Incorrect usage of Vector3.Dot? 0 Answers

Given a vector, how do i generate a random perpendicular vector? 5 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