Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Feref2 · Nov 10, 2018 at 01:03 AM · axisdistance

How can I get the distance between two points, but in just one relative axis?

Because is one relative axis, vector3.distance doesn´t work. Those points are collision points, and if the object that receives them is rotated, then that distance is diagonal. I want to get its relative x axis distance from collisions.

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 JVene · Nov 10, 2018 at 10:48 PM 0
Share

Distance along the x axis is merely the absolute value of the difference (subtraction) of the x coordinates.

avatar image Feref2 · Nov 17, 2018 at 07:46 AM 0
Share

@JVene correct me if am wrong, but I think that Vector3.Distance takes the distance like the red line: alt text

And I need the blue one, which i can´t get by substracting the x coordinates like you say, because that would give me something like this: alt text

captura-de-pantalla-19.png (147.8 kB)
captura-de-pantalla-20.png (147.4 kB)
avatar image JVene Feref2 · Nov 18, 2018 at 03:59 AM 0
Share

What you're looking for is a local relative X axis (local being key to recognizing what you're looking for). Your diagram is the most informative on this point, as I'm not entirely sure there's a clear label.


Note, by your diagram, the blue line will be the width of the rectangle, so if you know that you can just take it. Otherwise, your solution is trig, but could be be basic Pythagoras, in a sense. The distance of the red line is the hypotenuse. Unfortunately, you next need the base (the line of the implied triangle you haven't drawn). That is the distance of apparently the local y coordinates of the two points, from which you can algebraically swap Pythagoras around a bit to get the other leg.


On the other hand, you have a right triangle. If you could calculate the angle between where the red and blue meet, you can deduce the rest (the third is 90), and with the length of the red line you can use law of sines to complete the triangle and thus know the blue line length.


However, you might find it simpler to "unrotate" the object itself, or more accurately, unrotate the two points to a world axis alignment. Then the blue line would be merely a subtraction of the x coordinates.

avatar image Feref2 JVene · Nov 18, 2018 at 05:05 AM 1
Share

Thanks for your detailed explanation. I also thought making use of trigonometry the same way you did. However, depending on the leg of the triangle, the use of sine or cosine was different. I was having trouble identifying which to use, since the points may differ from the diagram and sometimes I will get them only when the object is rotated and other things that really confused me. But then you say there´s a simpler solution, "unrotate to world axis alignment". How can I achieve that?

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

157 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 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 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 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 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 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 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 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 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

How to instantiate a platform each time another platform is 3 units away from the gamecontroller? 0 Answers

¿como instanciar una plataforma cada vez que otra plataforma este a 3 unidades de distancia del gamecontroller? 0 Answers

Snap to grid 2 Answers

How to find current vertical axis 1 Answer

How to make an object move in the direction another object is facing on 2 axis? 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