Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by niteshrathi55 · Jun 18, 2018 at 05:01 PM · animationnavmeshagentanimator controllerenemy ai

EnemyAI movement stop if it has enable animator controller

I'm making enemy ai for my fps game. I create a cube and attach animator controller and NaveMeshAgent to ti. And i make simple enemy AI script. I'm using NaveMeshAgent, All thing work great until if i don't enable animator controller. This is my enemy AI script.

using UnityEngine; using UnityEngine.AI; using System.Collections;

public class EnemyAI : MonoBehaviour {

 public float eHealth = 100f;
 public bool isDead;
 Transform target;
 NavMeshAgent nav;
 Animator anim;

 void Start()
 {
     nav = GetComponent<NavMeshAgent> ();
     anim = GetComponent<Animator> ();
     target = GameObject.FindGameObjectWithTag ("Player").transform;
     isDead = false;
 }

 void Update()
 {
     if (eHealth < 0.1) {
         anim.SetBool("Dead", true);
         Destroy(gameObject, 3);
         isDead = true;
     }

     nav.SetDestination (target.position);
 }

}

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 tormentoarmagedoom · Jun 19, 2018 at 10:10 AM

Good day.

If your animation controls the position of the object, i supose the navmesh agent will go crazy... If you need to animate position and use navmeshagent, dont do it in the same object.

I better to have a empty parent with the NavMeshAgent, and a child with the animation.

Bye!

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 niteshrathi55 · Jun 19, 2018 at 11:15 AM 0
Share

Thank you for replay sir, It's working now but it's create a new problem for me. if i attack rigidbody to my enemy ai. its moving but dead animation is stuck not working properly. when enemy dead, its goinng to y axis. but if i remove rigidbody and navmeshagent. its all working fine!alt text

using UnityEngine; using UnityEngine.AI; using System.Collections;

public class EnemyAI : $$anonymous$$onoBehaviour {

 public float eHealth = 100f;
 public bool isDead;
 Transform target;
 Nav$$anonymous$$eshAgent nav;
 Animator anim;

 void Start()
 {
     nav = GetComponent<Nav$$anonymous$$eshAgent> ();
     anim = GetComponent<Animator> ();
     target = GameObject.FindGameObjectWithTag ("Player").transform;
     isDead = false;
 }

 void OnTriggerStay (Collider col)
 {
     if (col.gameObject.tag == "Player") {

         anim.SetBool ("Attack", true);
         FpsController player = col.gameObject.GetComponent<FpsController>();
         player.pHealth -= 0.1f;
     }
 }
 void OnTriggerExit (Collider col)
 {
     if (col.gameObject.tag == "Player") {
         
         anim.SetBool ("Attack", false);
         FpsController player = col.gameObject.GetComponent<FpsController>();
         player.pHealth -= 0;
     }
 }

 void Update()
 {
     if (eHealth < 0.1) {
         isDead = true;
         Destroy (gameObject);
     }

     if (isDead == false) {
         nav.SetDestination (target.position);
     }
 }

}

avatar image tormentoarmagedoom niteshrathi55 · Jun 19, 2018 at 04:05 PM 0
Share

Good day. I dont get exatcly what you say is happening.

But i recommend you to have all components (colliders, scripts, Rigidbody, etc...) except for animation in an empty gameobject that contains a child. In this child have the $$anonymous$$esh and the animation.

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

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

How do I make an animated AI enemy float but still move using NavMesh? 2 Answers

Blend Trees with NavMeshAgent 0 Answers

Rigidbodies stopping Root Motion of animations 0 Answers

Making your ai attack then return to the navmesh when player leaves trigger 0 Answers

I has a problem when i pressed "M" key animation not play. I mean amination play but not properly. Animation play properly when i hold "M" key? please help me. I want to play animation on single just click. 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