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 /
This question was closed Jun 27, 2011 at 02:36 AM by Waz for the following reason:

http://answers.unity3d.com/questions/135582/enemy-jitters-when-following.html

avatar image
0
Question by Xatoku · Jun 26, 2011 at 05:14 PM · playerenemymovingtowardsnudge

Enemy Nudging Towards Player

I've got my enemy to look at and chase the Player, but once he gets to the distance where he should stop chasing the Player, he'll do tiny nudges towards the Player, getting closer to him. Anyone have a clue why this is happening?

 if(targeted){ 
             var rotation = Quaternion.LookRotation(Player.transform.position - transform.position);
             transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
             transform.eulerAngles = new Vector3(0,transform.eulerAngles.y,0);
             ChasePlayer = gameObject.GetComponent("EnemyControl");
             if(distanceToTarget >= 3){
                 isMoving = true;
             }else{
                 isMoving = false;
             }
         }else{
             isMoving = false;
         }
     //CHASE THE PLAYER//
         if(isMoving && distanceToTarget >= 3){
             animation.CrossFade("run",0.2);
             var controller2 : CharacterController = GetComponent(CharacterController);    
             var forward : Vector3 = transform.TransformDirection(Vector3.forward);
             controller2.SimpleMove(forward * 3);
         }
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

  • Sort: 
avatar image
0

Answer by JonnyHilly · Jun 26, 2011 at 06:02 PM

because once he reaches the player he stops moving (or moves backwards a little to get to the limit radius/range), then next frame, he is out of range again, so he moves in range again, and this repeats... hence the jittery movement.

You can fix it in several ways... 1) make it so the enemy cant move faster than the player. 2) make it so the speed he chases the player is variable speed, not just true or false for chasing the player (more speed when further) less speed when very close (match player's speed)

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 Xatoku · Jun 26, 2011 at 06:38 PM 0
Share

You'll have to be more specific because I tried what you said and it still jitters.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Getting enemy to move towards player untill they collide problem... 2 Answers

Enemy raycast chase player 0 Answers

When the enemy character shoots, the bullet won't go to the position of my player! 2 Answers

If Player Looks At Enemy Script 4 Answers

How to make my player not lose health when attacking the enemy? 2 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