• 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 geraldfingburke · Jun 26, 2018 at 02:08 PM · rotationeuleranglesquaternionslookrotation

Rotation acting weird

alt text

As you can see in the gif, the rotation for my player entity is fine, but my enemy is acting weird. They share the same script, which I had written for a previous project with no issue. I don't get why it isn't working right here. Given that the script works fine everywhere else it's implemented, I thought there might be some issue with the gameobject, but I haven't found anything there that would cause this behavior. I appreciate any insight into the matter.

 private C1_PlayerController player;
 
     // Use this for initialization
     void Start () {
         player = FindObjectOfType<C1_PlayerController>();
     }
     
     // Update is called once per frame
     void Update () {
         Quaternion rot = Quaternion.LookRotation(transform.position - player.transform.position,Vector3.forward);
         transform.rotation = rot;
         transform.eulerAngles = new Vector3(0, 0, transform.eulerAngles.z);
     }

rotation.gif (368.2 kB)
Comment
Add comment · Show 2
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 Captain_Pineapple · Jun 26, 2018 at 03:19 PM 0
Share

what is the transform orientation for both enemy and player marker? is forward the actual direction they are looking in?

avatar image geraldfingburke Captain_Pineapple · Jun 26, 2018 at 03:32 PM 0
Share

It is. I threw a bunch of Debug statements in and I found that when I'm to either the left or right of the enemy sprite, moving the player along the y axis any distance only yields a rotational shift of 2 or 3 degrees total.

1 Reply

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

Answer by DrummerB · Jun 26, 2018 at 03:39 PM

Try this:

 void Update () {
     transform.right = player.transform.position - transform.position;
     // or transform.up, depending on which direction the arrow is pointing by default
 }

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 geraldfingburke · Jun 26, 2018 at 03:48 PM 1
Share

The simplicity of this solution is infuriating. You, sir, are a godsend. I've been banging my head against this for two days.

avatar image Captain_Pineapple · Jun 26, 2018 at 04:24 PM 0
Share

Holy . I thought I kinda know the basic tricks to handle transforms but i seriously did not know that one could directly set the rotations by defining the transforms global directions...

Well done!

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

121 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 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

Object deforms with rotation 1 Answer

Need help with storing Rotation in a Quaternion 1 Answer

Turret rotation on one axis problems 2 Answers

Look Rotation flipping object rotation after 180 degrees 1 Answer

Min-Angle Constraint Script Causes Jitter 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