Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 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
0
Question by diegobrego · Jan 25 at 10:45 PM · rotationvector3transform.positionanglemathf

Place object on radius pointing to a other object

Hi, I hope someone can help me with this, I know how to work in 2D but now I'm trying out something in 3D.

What i want to achieve is:

  • 2 objects with different rotation values are placed on a scene.

  • Connect the object via a tube.

  • The tube connector is placed pointing to the other object. (Image red circle)

My problem is, I can get the direction and so on, but this will place the object underneath the red circle, just where the blue line hits the mesh.

Can someone please help me or tell me how i can calculate the orange line pointing to the red circle?

alt text

problem.jpg (46.9 kB)
Comment
Add comment · Show 1
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 Riiich · Jan 25 at 11:17 PM 0
Share

Can you show an image of the result you're currently getting and using that image show what you would like to happen, please :)

1 Reply

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

Answer by Captain_Pineapple · Jan 26 at 09:18 AM

Hey there,

there are multiple ways to solve this but for this the easiest way is probably to use the power of the cross-product.

basically the result of a cross product of 2 vectors is a vector that is perpendicular to both vectors.

So if we define:

  • Left end of your lightblue line is P1

  • Right end of your lightblue line is P2

  • z-Axis through your left zylinder is cylinder_up

  • radius of your zylinder left is cylinder_R

Then you can calculate the point you are looking for by:

   var PointOnSurface = CenterOfLeftCylinder + (Vector3.Cross(Vector3.Cross(P2-P1,cylinder_up),cylinder_up).normalized * cylinder_R;

Basically Vector3.Cross(P2-P1,cylinder_up) calculates a helping vector which is perpendicular to your connectionLine P2-P1 and cylinder z Axis. Then taking the cross product with cylinder_up again gives you the line you want. (you might have to add a minus to the resulting normalized vector or switch the arguments of the cross product around since there are always 2 vectors that can be the result of the cross product. So depending on how unity works below the surface the resulting vector might point in the wrong direction by 180°.)


Let me know if that helped/something was unclear.

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 diegobrego · Jan 26 at 12:08 PM 0
Share

Thanks a lot, I used a workaround with raycasts, but this makes the code a bit cleaner ^^.

I'm going to analyze this to get a better understanding about it.

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

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

Velocity to 2D rotation (angle from velocity vector with atan2) 1 Answer

how to convert the angle to roatation? 1 Answer

Unity 8-Directional Locked Movement (Super Mario 3D World Style) 3 Answers

How do I find the angle between the players forward vector and the mouse position? 1 Answer

Get Direction from 2 Vectors - and Apply to Transform 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