• 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
Question by smtabatabaie · Feb 20, 2013 at 05:34 PM · rotationeulerangleslocalrotation

Get the Inspector's rotation of an object with code

Hi , I have a character which in the start of the game changes its rotation with a lookAt and looks at a point . and when I see the inspector the rotations of my character are (0.66,135,0) . but when I try to debug.log my character's rotation I get (0,0,0) . I have tried :
transform.rotation
transform.localRotation
transform.eulerAngles
transform.localEulerAngles

and all of them return (0,0,0)
is there any method to return exactly what I see in the inspector?
thanks

Comment
rad1c

People who like this

1 Show 5
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 PAEvenson · Feb 20, 2013 at 07:28 PM 0
Share

transform.localEulerAngles should give you what you see in the inspector. Im guessing you perhaps have the script on the wrong object?

avatar image smtabatabaie · Feb 20, 2013 at 08:48 PM 0
Share

yeah you're right , sorry I had attached it to another gameObject . but my problem still exists . my game is like this : my character changes its rotation with lookAt and then it's supposed to instantiate a bullet and shoot , but the bullet goes on the previous rotation of my character . and doesn't follow the rotation of lookAt .

avatar image smtabatabaie · Feb 20, 2013 at 09:14 PM 0
Share

I think it's Csharp , if i write it in javascript , the rotation changes with lookAt . I think I have to rewrite my scripts in javascript

avatar image robertbu · Feb 20, 2013 at 09:59 PM 0
Share

Your issue has nothing to do with C# or javascript. I suspect that you are not selecting the right object to use as a spawn point for the bullet, or you are using the wrong vector to apply the force. Typically I put an empty child object just in front of the gun as a spawn point. When you apply force, you can either use Rigidbody.AddForce(transform.forward), or you can use Rigidbody.ApplyRelativeForce(Vector3.forward).

avatar image smtabatabaie · Feb 21, 2013 at 06:28 PM 0
Share

Thanks , you're right it had nothing to do with C# or javascript (though I rewrote all of my scripts on javascript!) . it was the order of execution . I had several scripts which they referred to each other , i put the critical ones in one script and it worked! so far my experience in unity tells me to reduce the number of script as low as possible .

0 Replies

  • Sort: 

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

Complicated Rotation Issue 1 Answer

how to apply overall rotation to collection of rotated objects 0 Answers

How to use Euler angles to rotate an object ? 5 Answers

How to set an exact Local angle. 0 Answers

Setting rotation of child GameObject 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