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 Pauls · Nov 23, 2012 at 01:08 AM · transformvector3magnitude

Find a point with Vector and magnitude?

Hi,

i would like to find a point with a vector (starting point) and a magnitude, but i am a bit confused :

i throw a sphere up in the air, and when it starts coming down, i keep the position and set "y" to 0. (my new vector)

Then i would like to start from this new Vector, and add the same magnitude as from the old starting point and this new vector.

But when i instantiate a new cube at this destination point, this is not working, the cube is in the air, and i think i misunderstood something, how to calculate a vector and a magnitude to find another vector :

 function Update () {
     if (startOff){
         bestY = transformR.position.y;
         if (oldY < bestY) oldY = bestY;
         else if (oldY > bestY && !vectorAlreadyFound){
             
             vectorMiddlePoint = Vector3(transformR.position.x, 0, transformR.position.z);
             pref = Instantiate(Resources.Load("pref", GameObject));
             pref.transform.position = vectorMiddlePoint;//WORKS WELL
             
             distWithMiddlePoint = (vectorMiddlePoint - startingPoint).magnitude;
             
             //DESTINATION POINT (vector & magnitude)
             pref2 = Instantiate(Resources.Load("pref", GameObject));
             //pref.transform.position = transformR.forward * distWithMiddlePoint;
             pref.transform.position = (vectorMiddlePoint - startingPoint) * distWithMiddlePoint;
             
             vectorAlreadyFound = true;
         }
     }    


Would you know how to achieve this?


SOLUTION (thanks to you guys) :

 pref2.transform.position = ((vectorMiddlePoint - startingPoint).normalized * distWithMiddlePoint) + vectorMiddlePoint;
 pref2.transform.position.y = 0.0;


Thanks

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

3 Replies

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

Answer by Democre · Nov 23, 2012 at 01:58 AM

I think you would need to do something like:

 pref2.transform.position = ((vectorMiddlePoint - startingPoint).normalized * distWithMiddlePoint) + startingPoint;

You are then getting a unit vector in the desired direction, multiplying it by the desired length, and then adding that to the starting point.

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 Pauls · Nov 23, 2012 at 02:46 AM 0
Share

@Democre you are perfectly right, thanks a lot for your answer, i completely forgot about the offset at the end. I added the new vector and y=0 (i don't know why it did not do it automatically, my edit in the first post). Thanks again!

avatar image
1

Answer by Loius · Nov 23, 2012 at 01:17 AM

You're using pref instead of pref2 at the end, there.

Comment
Add comment · Show 3 · 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 Pauls · Nov 23, 2012 at 01:34 AM 0
Share

@Loius thanks, nice, i was a bit tired i think, so the cube appears way too far from where it should be, i would like to take the same direction, and add the magnitude, could you help me with that?

avatar image Loius · Nov 23, 2012 at 02:45 AM 1
Share

If you want such a thing as:

o-(X units)-m-(X units)-b

Where O $$anonymous$$ and B are Vector3, and O is the origin, $$anonymous$$ is the sphere (midpoint), and B is the new cube's position, then:

b = m + (m-o);

avatar image Pauls · Nov 23, 2012 at 02:48 AM 0
Share

Thanks Loius

avatar image
1

Answer by Loius · Nov 23, 2012 at 02:56 AM

It sounds like you're trying to do this:

"While standing on an infinite, flat plane, you throw a ball from Point Zero, forward and into the air. When the ball reaches the apex of its curve, it is assumed that it has moved half as far relative to the plane as it shall move before landing. Place a box at the ball's landing point."

If that's the case, then:

Your midpoint is equal to (flattenedApex - origin). To get the (vertically) flattened apex, you just set its .y component to the origin's .y component. I think, with your variables, that's vectorMiddlePoint.y = startingPoint.y

The landing point is that far again from the midpoint: targetPoint = flattenedApex + (flattenedApex - origin);

To use a magnitude, you need a concept of "direction" (a vector can represent either a position or a direction, but not both [except when engineered to; hush]). The 'direction' in this case is (flattenedApex-origin); normalizing that allows you to scale it to the desired length, but check how funny it looks:

targetPoint = origin + (flattenedApex-origin).normalized (flattenedApex-origin).magnitude 2.0;

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 Loius · Nov 23, 2012 at 02:57 AM 0
Share

skulks off to overanalyze something else now X)

avatar image Pauls · Nov 23, 2012 at 03:39 AM 0
Share

Thanks for the explanation, issue solved, thanks for the answers

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

11 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

Related Questions

Moving a Platform 1 Answer

Why using = isn´t fast enough for changing Vector3 values from the transform? 2 Answers

Transformations 2 Answers

gravity causes transform.position not to work 0 Answers

Player rotation = Camera Rotation 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