Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 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 ProudOne · Jul 08, 2012 at 11:55 AM · 2dgui3dpointat

2D Arrow pointing at 3D Position

This is probably a really stupid, easy to solve problem. It feels like one of these things where you lack a fresh perspective or the programming vocab to pull it off; So here's my Problem:

For my GUI I have a 2D Arrow in 3D Space that is supposed to rotate on its Y-axis to point at a 3D Object. I'm not struggling with the mental model on this, just the execution has escaped me for the past week. Here's the Arrow:

alt text

This is the hierarchy its in:

alt text

Control being the player's GameObject. Basically this is how I thought to do it: Transpose the position into local space using InverseTransformPoint, then use Math.Atan2 to calculate the angle. That doesn't work and I don't understand why.


 tmpVector = arrow.InverseTransformPoint(objectToPointAt.position);
 arrow.localEulerAngles = new Vector3(0, Mathf.Atan2(tmpVector.y, tmpVector.z) * Mathf.Rad2Deg, 0);

Thanks in advance for any hints!

Comment
Add comment · Show 3
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 ProudOne · Jul 08, 2012 at 03:32 PM 0
Share

The Arrow is sitting in the X-Z Plane. So for the arrow to point, say, to the left side, you'd rotate it 180° on the Y axis. The Camera's view direction changes depending on where the player looks.

avatar image ProudOne · Jul 08, 2012 at 03:54 PM 0
Share

The TT is actually a Plane, so is the player. So the TT can be anywhere in space around the Player. So nah, the TT's Y Value is probably never the same as the Arrow's...

avatar image ProudOne · Jul 08, 2012 at 04:05 PM 0
Share

Oh gosh yeah, a litteral Aeroplane XD. I feel pretty dumb for not having mentioned that!

1 Reply

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

Answer by ProudOne · Jul 09, 2012 at 11:02 AM

As I expected, the answer was actually right in Front of me all the time. I needed to add 180 to realign the arrow.


tmpVector = player.transform.InverseTransformPoint(allyIsland.position); // Transfer the point into the local space of the arrow
angleToTarget = Mathf.Atan2(tmpVector.x, tmpVector.z) * Mathf.Rad2Deg; // Calculate the Angle the arrow needs to rotate
angleToTarget += 180.0f; // Add 180 Degrees
guiAllyIslandDir.localEulerAngles = new Vector3(0, angleToTarget, 0); // Rotate!

Thanks, everyone! Here's where I feel really dumb ^^

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

7 People are following this question.

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

Related Questions

A 2D GUI in mid air, for oculus, tracking an object. 1 Answer

Fix a GUI's position relative to a 3D object 1 Answer

2D object Image Look at 3D object Pointing 1 Answer

GUI Follow RaycastHit 2 Answers

Convex Mesh Collider on Procedurally generated mesh does not conform.. 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