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 seanybaby2 · Jan 30, 2018 at 06:09 PM · eulerangleslocal space

How to get the localEulerAngle Transform.Right that is being set from a world rotation without setting it to a transform.

Basically I'm trying to get the LocalEulerAngle of the base.transform.right position that is being set by the lookAtPos. I want to get this value without the need to set the value to the transform. This way I can do some detection on the LocalEulerAngle before setting it to the transform.

  Vector3 lookAtPos = (target.transform.position - base.transform. position).normalized;
         
          base.transform.right = lookAtPos;
 




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 seanybaby2 · Jan 30, 2018 at 06:10 PM 0
Share

Basically I want the LocalEulerAngle of the base.transform.right that is being set by the lookAtPos without having to set the base.transform.right. Preferably using some Vector3 $$anonymous$$ath.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Glurth · Jan 30, 2018 at 10:20 PM

Not sure exactly what you mean... if you want to make your transform.right face the lookAtPos, you could do something like this:

 using UnityEngine;
 
 public class lookatTest : MonoBehaviour {
     public Transform lookat;
     void Update () {
         Quaternion lookAtRot = Quaternion.LookRotation(lookat.position-transform.position);
         Quaternion lookRight = Quaternion.LookRotation(-Vector3.right);
         Quaternion finalRot = lookAtRot * lookRight;
         Debug.Log("finalRotEulers:" + finalRot.eulerAngles);
         transform.rotation = finalRot;    //sounds like you DONT want to do this, for some reason
 
     }
 }

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 Owen-Reynolds · Jan 30, 2018 at 10:36 PM 0
Share

A key in this answer is LookRotation. 'Quaternion.LookRotation(target.pos - transform.pos)` computes the same angle that LookAt(target) would have set. That's actually how LookAt works. You can always use LookRotation to test-compute what LookAt would do.

Hmm.. seems like lookAtRot*Quaternion.Euler(0,90,0) would be simpler to compute the final local-right. Is the original lookAtRot facing backwards on purpose?

Back to the intent, it's safe to set a rotation using LookAt, sample it, then change it back. It's the same as x=3; x=5;. $$anonymous$$aybe it's ugly, but if it makes the game work... .

avatar image Glurth Owen-Reynolds · Jan 31, 2018 at 01:38 AM 0
Share

Good catch, I got both the vectors backwards! Should be lookat.position-transform.position and -Vector3.right.. I'll edit the answer.. "Simpler" to specify Euler angles: I like this format because sometimes (not in this case) one might want to use something like this:

 q=Quaternion.LookRotation(transform.right);


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

75 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

Related Questions

Rotation problem 0 Answers

Euler angles doesn't give correct value. 0 Answers

Problem rotating camera on negative z axis 1 Answer

Limit movement to just forward/backward and left/right 0 Answers

Flipping cards to face camera at weird angles 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