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 Ari Levi · Jan 15, 2012 at 06:55 AM · vector2relative

returning a relative Vector?

I have 3 vector3s and I need to get the relative Vector2(from V3 on the orange plane). How can I do this?

alt text

Comment
Add comment · Show 5
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 Ari Levi · Jan 15, 2012 at 10:15 AM 0
Share

Sorry, I'll try clarify. So far I have generated these 3 vectors, Using Vector3.OrthoNormalize().

They are all based off V1 which I can move around in 3d space so it can be any direction(not just flat) I am happy with the way they relate to each other: As I can rotate them in space and they behave fine.

What I want is the Vector2 version of V3 considering V2 as the reference for UP or y axis and V1 is the z axis.

The plane that V3 is on is perpendicular to V1 and this plane (shown in orange). This is the relative plane that I want to derive my values from.

avatar image Ari Levi · Jan 15, 2012 at 10:48 AM 0
Share

yes it would be easy if I used a gameObject, rotated it and used it's local axis, but you are right. I want to do just that without the use of a transform. hmmm... I look at some other forums and see what I find

avatar image Bunny83 · Jan 15, 2012 at 11:05 AM 0
Share

All the math needed isn't difficult, but you need a concrete problem to be able to solve it. However I still don't get what V3 should represent. Your drawing looks like 3D space.

Do you mean all 3 vectors are Vector3-vectors and you want to project your the third one onto the plane defined by V1 and V2?

avatar image Ari Levi · Jan 15, 2012 at 11:27 AM 0
Share

yes, all 3 are are vector3, and I already have V3 moving on the plane defined by V1 and V2, but I want the value of V3 as a VECTOR assu$$anonymous$$g that V1 is the relative UP, sort of like a local XY axis.

so AT$$anonymous$$ all 3 vector could be facing any direction in 3d space but I need the value of V3(relative to V2 as Up) to used as a UV offset(Vector 2).

avatar image Ari Levi · Jan 15, 2012 at 12:15 PM 0
Share

Bunny83- Cheers I managed to get the effect I was after using InverseTransformDirection :) $$anonymous$$any thanks :)

2 Replies

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

Answer by Bunny83 · Jan 15, 2012 at 11:25 AM

Ok, i just re-read your clarification. Do you mean your plane's normal is your forward vector (red), V2(green) is your local upvector and V3 is an arbitrary vector that should be projected onto this plane? Some kind of head-up-display position?

If that's the case you can just use InverseTransformDirection of your transform and transform the vector3 into local space. Cancel out the z-part to project it to the local x-y-plane, that's all.

edit : Converted my comment into an answer ;)

second edit
If you want to convert the position manually into your own local 2d coordinate system, you need the two axis first. One axis would be your up-vector and the other missing vector your right-vector.

This one can be calculated with the cross-produkt(wiki). Since Unity uses a left-handed-system you have to swap the two vectors to get the right- instead of left-vector.

now you can simply project your desired vector onto those two (normalized) vectors to get the desired x-y coordinates:

// C# Vector3 forward; Vector3 up; // have to be normalized

Vector2 TransformPointIntoPlane(Vector3 aPoint) { Vector right = Vector3.Cross(up, forward).normalized; // If forward is also normalized you don't have to normalize "right" here. // If both of your axis-vectors are normalized you don't have to use Vector3.Project // the dot-product is enough: return new Vector2(Vector3.Dot(aPoint,right),Vector3.Dot(aPoint,up)); }

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 tylo · Jan 15, 2012 at 10:19 AM

 Vector3 heading = (target.transform.position - transform.position).normalized;

This should give you the relative direction of one Vector to another. I might have those two terms backwards, I can never keep them straight.

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

8 People are following this question.

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

Related Questions

The speed is changing every second 1 Answer

Looking to see if the method I'm using for movement is correct or if I'm doing something wrong. 0 Answers

gui position of Screen relative position 2 Answers

Keep GUIText in a relative position for different devices 1 Answer

Place object relative to player location 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