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
1
Question by MrLolEthan · Oct 12, 2012 at 11:38 PM · rotationaizombie

My Zombie Model is coming at me sideways with the AI

Ok so I have my AI script and an empty gameobject declared a trigger so when you come in contact with the trigger the enemy comes at you. So the enemy follows me but he is turned sideways and he adjust's sideways even if I move in front of him. I'm thinking the problem is that the game thinks the side is his face and turns it to adjust there. Can someone help me fix this please?

My AI Script Code:

 var target : Transform;
 var enemy : Transform;
 var moveSpeed : float = 1.0;
 var inRange : boolean = false;
 
 function OnTriggerEnter() {
     inRange = true;
 }
 
 function OnTriggerStay() {
     inRange = true;
 }
 
 function OnTriggerExit() {
     inRange = false;
 }
 
 function Update() {
     if(inRange == true) {
         enemy.transform.LookAt(target);
         enemy.transform.position = Vector3.Lerp(
         enemy.position, target.position,
         Time.deltaTime * moveSpeed);
         enemy.animation.Play("Take 001");
         enemy.animation.Stop("idle");
     }
     
     if(inRange == false) {
         enemy.animation.Stop("Take 001");
         enemy.animation.Play("idle");
     }
 }

PS Ignore the animations

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
1
Best Answer

Answer by aldonaletto · Oct 12, 2012 at 11:58 PM

transform.LookAt points the object's Z axis to the target transform (or position). If the enemy is looking in the wrong direction, it's not facing the Z axis - maybe its front side is in the X direction instead. The simplest way to fix this is to replace the LookAt instruction with something more versatile, like this:

 if(inRange == true) {
     var dir = target.position - enemy.position; // calculate the target direction
     dir.y = 0; // keep the direction strictly horizontal
     // rotate enemy's right side to the target
     enemy.rotation = Quaternion.FromToRotation(Vector3.right, dir);
     enemy.transform.position = Vector3.Lerp(...

This code rotates the enemy right direction to the target. If it's not ok, try Vector3.left instead.

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 MrLolEthan · Oct 13, 2012 at 02:48 PM 0
Share

Thank you!

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

10 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

looking to make for a zombie script AI,navmesh or not? 2 Answers

Random movment, like mobs in wow 1 Answer

ZOMBIE AI SCRIPT 1 Answer

Damage trigger? 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