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 HtmHell · Jun 05, 2014 at 10:32 AM · rotationrotatedirection

Rotate a GameObject [set front]

I have two GameObjects. one is the player, and one is the enemy. I have a code that rotates the enemy to the player's direction:

var rotation =

Quaternion.LookRotation(Target.position - transform.position);

transform.rotation =

Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping); The problem is that the ememy's front is the back. The enemy turns his back to the player, instead of his front. (not a code problem) How can I fix it? Thank you, and sorry for my English
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by MSpiteri · Jun 05, 2014 at 10:36 AM

You have to make sure that the PARENT gameobject of the enemy has its Z-axis pointing in the enemy's FORWARD direction. This is VERY important when grouping objects.

To fix it, it depends on how the parent-children are in your game.

Comment
Add comment · Show 4 · 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 HtmHell · Jun 05, 2014 at 10:55 AM 0
Share

They both have the same parent. How can I fix it? (it's not a problem to remove them from this parent)

avatar image MSpiteri · Jun 05, 2014 at 11:16 AM 0
Share

Can you paste a screenshot of the Hierarchy panel so I can see how the enemy is constructed?

avatar image HtmHell · Jun 05, 2014 at 11:28 AM 0
Share

http://gyazo.com/a0c4894bcf26c243d452f2945d9a7ecd Please tell me if you need anything else... And thank you!

avatar image MSpiteri · Jun 06, 2014 at 10:38 AM 0
Share

Sorry for the late reply.

Ok, so you have that object called "Enemy" in the list. If you click on it and look at the "Scene" view, you will see the arrows for the x, y and z direction. The Enemy will move in the direction of the Z-ARROW (blue arrow).

($$anonymous$$ake sure that the settings at the top are "Pivot" and "Local").

So, most probably, your problem is that the Z-ARROW is pointing in the opposite direction. To resolve this, you can do this:

(1) Create a new empty gameobject and call it "test".

(2) $$anonymous$$ove all the children of "Enemy" inside "test". So "Enemy" will not have any children now.

(3) Rotate "Enemy" by 180 degrees around the Y-axis. So now the Z-ARROW of "Enemy" will point in the opposite way.

(4) $$anonymous$$ove back the children from "test" to "Enemy".

(5) Delete "test".

After the above, it should be ok :)

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 should I rotate a 2D unit vector by X degrees? 1 Answer

(Picture for Clarity) How do you click on an object, and from that hit point, calculate a direction vector, and then make that direction vector be the upwards direction of an object? 0 Answers

Set rotation based on 2 points problem 1 Answer

Rotate but keep direction 1 Answer

How can I move an object to click point in 2D? 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