• 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 rimawi · Feb 26, 2011 at 07:30 PM · rigidbodyai

AI issue...Enemy stops after a while

Hi,

I have an enemy with a rigidbody attached to it and a capsule col1ider:

the Ai on it:

// Thank to : //http://answers.unity3d.com/questions/41958/ai-enemy-scripting-help

var distance; var target : Transform;
var lookAtDistance = 15.0; var attackRange = 10.0; var moveSpeed = 5.0; var damping = 6.0; private var isItAttacking = false;

function Update () { distance = Vector3.Distance(target.position, transform.position);

 if(distance < lookAtDistance)
 {
     isItAttacking = false;
     animation.CrossFade("butt");
     lookAt();
 }   
 if(distance > lookAtDistance)
 {
     animation.CrossFade("idle");
 }
 if(distance < attackRange)
 {
     attack();
     animation.CrossFade("walking");
 }
 if(isItAttacking)
 {
     animation.CrossFade("walking");
 }

}

function lookAt () { var rotation = Quaternion.LookRotation(target.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping); }

function attack () { isItAttacking = true; animation.CrossFade("walking");
transform.Translate(Vector3.forward * moveSpeed *Time.deltaTime); }

The problem is he stops chasing after awhile even if i stand in its face

is if something gets reset

why I chose rigidbody - for collision >> because the player has a character Controller >> if I add character controller to the enemy I will have issue with collision between two character controller

So Any ideas how can get rid of the issue on the enemy

thank you

Comment
Add comment · Show 4
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 FLASHDENMARK · Feb 26, 2011 at 09:06 PM 0
Share

First of all you are welcome :)

, but I dont see a problem in your script. I tested it out with a cube with a rigidbody attatched and of course deleted all the stuff inclouded animations and it works as supposted to. Try deleting you lines of code involving animations, and see if that is the problem.

avatar image rimawi · Feb 26, 2011 at 09:38 PM 0
Share

I tried it without my animation on a cube.

Same issue happed.

I am using a terrain - it has ups and downs.

most likely that what is causing the issue.

I have angular drag =0 drag=0;

Thanks again

avatar image AngryOldMan · Feb 28, 2011 at 12:22 AM 0
Share

Find out exactly what actions you do when the enemy stops following you. try putting debug logs in each of the if statements and seeing exactly what you do that makes the enemy stop.

avatar image rimawi · Feb 28, 2011 at 01:02 AM 0
Share

usually, That happens after the lookat and if the player Y is too high like on a hill.

I decided to go with the character controller ins$$anonymous$$d of rigid body.

the character controller does not have the issue.

and ins$$anonymous$$d of doing collision between the controller I just see how close they are to each other.

Thank all for your help.

0 Replies

· Add your reply
  • Sort: 

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Auto-moving RigidBody2D to a point, using thrusters (part of AI) 0 Answers

How to Add Knockback Force Based on What Rotation it Came From 2 Answers

Enemy Rigidbody Not Responding to Gravity 1 Answer

FPS RIGIDBODY PROBLEM 1 Answer

How do I make this kind of follow script? 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