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
0
Question by Trustler300 · Feb 25, 2015 at 11:53 AM · follow player

Follow AI Script , AI gets launched

Hi i'm having an issue on every follow ai script i try on my AI. I have a zombie thats supposed to chase me when i get near but instead of following me when in range, it gets launched as soon as i get close. This is the code i'm using currently

  var target : Transform;
  var moveSpeed = 20;
  var rotationSpeed = 5;
  var myTransform : Transform;
  var minDistance = 50;
       
  function Awake()
  {
      myTransform = transform;
  }
       
  function Start()
  { 
      target = GameObject.FindWithTag("Player").transform;
  }
       
  function Update () {
       if(Vector3.Distance(myTransform.position, target.position) < minDistance) {
         
         myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
         Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
         myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
      }
  }
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 Baste · Feb 25, 2015 at 01:25 PM

That code should move the zombie 20 units per second, as the moveSpeed is 20. With one unit generally being 1 meter, that would be 20 meters each second. That's 72 km/h or if you're American, ~45mph.

Unless your zombies are actually zombie cars, or everything is at a really large scale, I'd suggest tuning the movespeed back a bit.

At the same time the rotation speed is very low. You're rotating the zombie 5 degrees every second, which means that it will take it 72 (360/5) seconds to turn completely around.

So, if you approach the zombie from behind, it will zoom away from you at the speed of you average car on a highway, and turn to face you over the duration of about half a minute. Which isn't really what I'd call "chasing".

If your models are human sized (a bit less than two standard Unity cubes tall), a good rotation speed is usually in the ballpark of 180-360 degrees per second, and movement speeds in the range of 3-6 seems natural. All depending on your application.

Finally, I'd advice you to not move the zombie directly forward, but instead towards the character. If you approach it from behind, it'll look a bit weird, but not as weird as if the zombie starts walking away from you in a little loop. So your movement code would be:

 var toTarget = (target.position - myTransform.position).normalized;
 myTransform.position += toTarget * moveSpeed * Time.deltaTime;
Comment
Add comment · 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Make object follow player on trigger 0 Answers

Following a gameObject, unexpected problems? 1 Answer

how to make the camera follow the player only in one axis (the z axis) 0 Answers

Trying to refrence my selected character for AI follow, I'm stumped. 5 Answers

NPC that follows me tilts backwards as he get too close to me. 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