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 ThiagoTejo · Dec 16, 2013 at 03:39 PM · vector3axisdistance

Whats the best way to get the Distance between two Vector3?

I know that the best way to get the distance for a Vector3 is using Vector3.distance, etc, etc. But what I'm looking for here, is how to get the Distance between the two "local X axis" for both Vector3 and their rotations. I don't know how to explain this so well, so I made this image:

alt text

I want to know the "gap" between these two positions, for exemple. Both are facing the same way, and have the same Y position ( are on the same height ) So they differ on the X and Z axis. I want to get the distance between them using a perpendicular axis. Ahn, I really dont know how to write this down, but I guess you guys understood...

I know how to do this using global values, for exemple, the global X axis or Z, like the first image, but I need them to be rotated, how do I do this?

distance.png (1.6 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

2 Replies

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

Answer by Owen-Reynolds · Dec 16, 2013 at 04:50 PM

Not sure what the end result you want is, but: Often converting to local space of one object can help. Standard practice for people who do this sort of math. From memory:

 vector3 p2 = thing1.InverseTransformDirection(thing2.position - thing1.position);

Math notes: t1-t1 a the world direction. ITD turns a world into a local direction.

In the second picture, p2 is now something like (12,0,-2). Where 12 is the long "thing1 x" line you drew, and -2 is the distance backwards to the tip. In other words, how to find things2, starting from thing1 and using it's RGB arrows.

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 ThiagoTejo · Dec 16, 2013 at 05:00 PM 0
Share

Thank you!! That's exactly what I was looking for :)

avatar image flaviusxvii · Dec 16, 2013 at 05:07 PM 0
Share

Haha, I'm glad you like this answer but the fact that this is what you meant just confuses me even more. Carry on.

avatar image
1

Answer by flaviusxvii · Dec 16, 2013 at 03:52 PM

Vector projection is what you are looking for. It'll take the vector between the two positions and then you can constrain that vector to the XZ plane (or whichever plane you like).

http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Project.html

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 ThiagoTejo · Dec 16, 2013 at 04:08 PM 0
Share

Thanks, I'm taking a look at this, it seems complicated, but i'll keep trying. If you could explain me a little bit how to achieve what I want, i would be thankful ^^ If not, its good too :) Thanks anyway! (Sorry for bad english...)

avatar image Owen-Reynolds · Dec 16, 2013 at 06:13 PM 0
Share

One way to project onto A is: convert to A's local coords, take the local z only, covert back to global. So, if what you want is "kind of like projecting," using local-coords is like doing a slow projection, with more chances to jump in and change things.

Plus projections and basis changes can be difficult to visualize. It seems like people tend to either "get" one or the other.

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

18 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

Related Questions

Find gameobject furthest from player along z axis 0 Answers

Set Distance to object 1 Answer

if close to one of a kind? 2 Answers

Distance Variable Won't Change. What's Wrong With My Script? 1 Answer

Reposition to minimum distance from target 2 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