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 Buzzbomb · Apr 30, 2014 at 05:14 PM · c#transformeuleranglesset

How do I set an objects euler rotations to match the objects transform in C#?

I have a script that is almost functional, it gives some good output as to where the player is standing relative to where an object is facing...this could be used to adjust a texture offset with some billboarding to recreate those good ol' original Doom style enemies.

My problem is that the euler transforms are constant and have nothing to do with an object's rotations or transform. I can debug my game with an object facing me and the console says he is facing me...I rotate the object by 180 and it still says he is facing me.

Is it possible to 'zero out' the object's eulers to match the objects transform in the update in C#?

Also would those adjusted euler angles be set for only that object or would this adjust the calculations for every code using eulers in the game?...basically a catastrophe...

Comment
Add comment · Show 4
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 flaviusxvii · Apr 30, 2014 at 05:29 PM 0
Share

We'd need to see some code to help. I would strongly suggest that you embrace Quaternions though. Working with Euler angles breaks down quickly if you have object hierarchies deeper than two levels.

avatar image Buzzbomb · Apr 30, 2014 at 05:45 PM 0
Share

the Top calculates the horizontal calculations and the lower the vertical...I get some great output into my console but it never adjusts based on which way the object faces.

 using UnityEngine;
 using System.Collections;
 
 public class facedebug : $$anonymous$$onoBehaviour {
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
 
                 
         
             var dir = Camera.current.transform.position - transform.position;
             var angle = ($$anonymous$$athf.Atan2(dir.z, dir.x) + $$anonymous$$athf.PI) * (180 / $$anonymous$$athf.PI); // range 0 to 360
             var horizatanindex = $$anonymous$$athf.RoundToInt(angle / 45) % 8; // range 0 to 7
         
             //Debug.Log (horizatanindex);
         
             var dir2 = Camera.current.transform.position - transform.position;
             var angle2 = ($$anonymous$$athf.Atan2(dir2.y, dir2.z) + $$anonymous$$athf.PI) * (180 / $$anonymous$$athf.PI); // range 0 to 360
             var vertatanindex = $$anonymous$$athf.RoundToInt(angle2 / 45) % 8; // range 0 to 7
         
             Debug.Log (vertatanindex);
     
     }
 }
avatar image Buzzbomb · Apr 30, 2014 at 05:46 PM 0
Share

...also the var's are aligned...my copy paste seems to have messed up the placement for the above post

avatar image Buzzbomb · Apr 30, 2014 at 05:58 PM 0
Share

To explain a bit more...this gives out a value between 0 and 7 based on where the camera is (not the player as I mistakenly posted before) in relation to where the object is facing...i.e. is the camera looking at the objects right-side, left-side, it's back, face etc. The vertical gives out put if youa re looking at the top of an objects head, the bottom of it's feet etc.

At least it should...The output I get seems correct but completely ignores where the object is actually facing and seems fixed somehow.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by wibble82 · Apr 30, 2014 at 05:32 PM

Hi there

The object's euler values are its rotation. Basically the transform stores the local position as a vector3, the local scale as a vector3 and the local rotation as a quaternion. Internally these are combined with the parent, and its parent and its parent etc etc to get its world position/scale/rotation.

The euler angles member on transform is a property (effectively a special function that doesn't need parameters) that:

  • when setting the euler angles, converts them to a quaternion then sets the rotation to the new value

  • when reading the euler angles, converts the rotation to euler angles then returns them

If you aren't seeing the euler angles change then there's something else odd happening. I would guess that somehow you're looking at the euler angles of the wrong object. If you can see your object is rotating then the euler angles should be changing. However, if its a child of an object that's rotating, its local rotation won't be (which is the one that is displayed in the transform in the property inspector).

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

22 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

Related Questions

How to go from eulerAngle axis 270 to 0 by rotating 90 degrees? 1 Answer

I can't set the rotation of an object, either with scripts or directly in the editor. 1 Answer

How to use an axis of a eulerAngle for a targetAngle on a HingeJoint? [C#] 0 Answers

Distribute terrain in zones 3 Answers

Particle System wont play? 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