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 Andrew_Lohmann · Jun 09, 2013 at 05:17 AM · transformobjectanglevector

Orienting multiple objects on the same line

Hello, I am trying to create a mini golf game. I am having a bit of trouble figuring out an issue. When the golf ball is at rest and has stopped moving, I would like the golf club to re-orient itself a short ways behind the ball. However, I would like it to be positioned in such a way that it is auto-aiming for the player, facing the hole. So, imagine if a line is placed from the center of the hole to the center of the ball, the golf club would be on that same line, just a bit behind the ball and facing the ball. I have looked into using Vector3.Angle and several other methods, but I am still a bit lost. Any help would be appreciated. Thanks a lot!

-Andrew

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

1 Reply

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

Answer by robertbu · Jun 09, 2013 at 05:25 AM

You can get placement like this:

 var v3 = (ball.transform.position - hole.transform.position).normalized;
 club.transform.position = hole.transform.position + v3 * ball_distance;

'ball_distance' is the distance you want the club away from the ball. Assuming you have the club constructed so that positive 'z' is forward, and the ball is rolling on the X/Z plane, you can do this to rotate the club:

 var v3 = hole.transform.position;
 v3.y = club.transform.y;
 club.transform.LookAt(v3);
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 Andrew_Lohmann · Jun 09, 2013 at 07:53 AM 0
Share

Oh, thank you so much, robertbu! This seems to work just fine :)

avatar image robertbu · Jun 09, 2013 at 07:54 AM 0
Share

Please click on the checkmark next to the question to close it out. Thanks.

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

14 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

Related Questions

Rotate an object around another object at an angle from the X axis? 1 Answer

Make an object move to a given point by rotating to the correct direction first. 1 Answer

Imported model is rotated 90 degrees off of straight, can't use any transforms 1 Answer

How to make Y-Axis face away from a position? 2 Answers

how to scale the transport? 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