Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
1
Question by bernardp · Jun 15, 2017 at 05:17 PM · scripting problemunity5

Enemy object model not facing the player correctly

I created an enemy object which has a model and wrote a script that makes the enemy face the player when the player is close. However, when I get close the model of the enemy is rotating wrong, i.e. it should be rotated 90 degrees to make the model face the player correctly. Here is a pic of the problem:

http://prntscr.com/fk6c5a

You can see how the model is facing the player sideways (and its like that all the time when following the player, I tried to somehow add 90 degrees to the enemy object and make the model face the player correctly but I don't know where to modify that or how. The code for rotation is this:

private void Update() { if (Vector3.Distance(igrac.position, this.transform.position) < 10) { Vector3 direction = (igrac.position - this.transform.position); direction.y = 0;

         this.transform.rotation = Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(direction), 0.1f);
     }
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 TeohRIK · Jun 16, 2017 at 07:41 AM 0
Share

is it because the front direction for your enemy is wrong? The front of your enemy should be facing on local Z-axis

1 Reply

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

Answer by HawkSandwich · Jun 16, 2017 at 08:03 AM

Heya :)

There are a few ways of doing this. One is to add 90 degrees on the next frame. It might look something like this:

 this.transform.rotation = Quaternion.Slerp (this.transform.rotation, Quaternion.LookRotation(direction), .1f);
 this.transform.Rotate(0, 90, 0); //this value might be on the wrong axis, or maybe it needs to be negative instead.

Of course, this isn't the most efficient way of solving the problem, but it's probably the simplest to understand.

Another way of doing this might be something like this, although I haven't tested it so it could be completely wrong.

 this.transform.rtation = Quaternion.Slerp (this.transform.rotation + Quaternion.Euler(0, 90, 0), Quaternion.LookRotation(direction), 0.1f);

I hope I helped :)

Comment
Add comment · Show 1 · 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 ShadDev · Feb 12 at 10:01 PM 0
Share

OMG YOU JUST SAVED MY LIFE I HAVE BEEN LOOKING EVERYWHERE FOR THE ANSWER THANK YOU SO MUCH

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

110 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

Related Questions

Checking materials that were assigned at runtime 0 Answers

Decal Rotation after instantiation 0 Answers

Raycast.normal vs collision.contacts[].normal which is better? 0 Answers

I'm having a problem with getting a door to open 1 Answer

The method StartHost() didn't work why ? 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