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 /
avatar image
0
Question by voongmc · Aug 18, 2016 at 05:12 AM · lookateuleranglesvector3.angletargetrotation

Moving On Two Axes and Reading a Stable Angle

Hi All!

This is my first time posting to this forum and I hope you can help me out. I am a complete newbie when it comes to Unity programming, but not programming in general.

What I'm Trying to Do: I am trying to make an instance of a spotlight follow a player object but only use two axes to do it (emulating a moving head type of light for a DIY WISYWIG visualizer). So, specifically, I have a moving light model containing a spotlight within a head which tilts on the X axis connected to another object which pans on the Z axis. My moving light object has within it a dummy light object which I use to look at the player object.

Specific Problem: Here is the crux of the issue: After looking at the player object using only the X and Z axes, I want to extract the rotation angle data so I know how many degrees pan and tilt resulted in the light focus.

Where I'm At: Using lookAt I have a light tracking an object but using XYZ. When I use slerp and lookRotation like so:

var targetPoint = new Vector3(targetObj.position.x, 0, targetObj.transform.position.z) - lightObj.position; var targetRotation = Quaternion.LookRotation(targetPoint); lightObj.rotation = Quaternion.Slerp(lightObj.rotation, targetRotation, 1);

the axes do not switch about during tracking, but the EulerAngles are unstable. I understand referencing the EulerAngles within unity isn't wise because there are many possible XYZ combinations for a given Quaternion. Hence this issue in general. I read about using Vector3.Angle to compare two vectors, and tried to do so as follows:

//lightObj is looking at the player while refLight is identical but static as a reference panAngle = Vector3.Angle(new Vector3(0,0,lightObj.rotation.z), new Vector3(0, 0, refLight.rotation.z)); tiltAngle = Vector3.Angle(new Vector3(lightObj.rotation.x,0,0), new Vector3(refLight.rotation.x,0,0));

After much experimentation I have run up against a knowledge wall and I know no one personally experienced with Unity programming.

Any help you could offer will be greatly appreciated!

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

LookAt on only 1 axis for 2D games? 1 Answer

LookAt script Issues 0 Answers

Look Rotation flipping object rotation after 180 degrees 1 Answer

lookAt euler angles 3 Answers

Trying to have object spin within player and always face "up" relative to camera [example pics of what I'm trying to achieve in post]] 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