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 /
This question was closed Apr 08, 2013 at 07:18 AM by AlucardJay for the following reason:

Other : question has been answered before, and can be found by searching

avatar image
0
Question by D3m0nE · Apr 07, 2013 at 10:04 PM · aienemymovefollow

How To Make Enemy Move Around

Hello Everyone i use SpawnScript to spawn enemy

and when i get close enemy, he try to follow me

but the problem that if he didn't saw me, he keep stand in his position

i want him to move around

 if(distance > lookAtDistance)
 {
 
 //MOVE ARROUND    
             
 }


i just tried very simple code :

 transform.position = Vector3.Lerp(transform.position, transform.position + new Vector3(1,0,1), 0.2f);

but he keep moving forward until he fall from the terrain xD

i need him to move around his range, almost like circle way

Comment
Add comment · Show 1
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 dandelo99 · Apr 05, 2016 at 04:30 PM 0
Share
 #pragma strict
  
 /// <summary>
 /// Creates wandering behaviour for a CharacterController.
 /// </summary>
 @script RequireComponent(CharacterController)
  
     var speed:float = 1;
     var directionChangeInterval:float = 1;
     var maxHeadingChange:float = 30;
  
     var heading: float=0;
     var targetRotation: Vector3 ;
  
     function Awake (){
  
         // Set random initial rotation
         transform.eulerAngles = Vector3(0, Random.Range(0,360), 0);  // look in a random direction at start of frame.
  
         //StartCoroutine
         NewHeadingRoutine ();
     }
  
     function Update (){
         var controller : CharacterController = GetComponent(CharacterController);
  
         transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, targetRotation, Time.deltaTime * directionChangeInterval);
         var forward = transform.TransformDirection(Vector3.forward);
         controller.Simple$$anonymous$$ove(forward * speed);
     }
  
     /// <summary>
     /// Repeatedly calculates a new direction to move towards.
     /// Use this ins$$anonymous$$d of $$anonymous$$onoBehaviour.InvokeRepeating so that the interval can be changed at runtime.
     /// </summary>
     while (true){
         NewHeadingRoutine();
         yield WaitForSeconds(directionChangeInterval);
     }
  
     /// <summary>
     /// Calculates a new direction to move towards.
     /// </summary>
     function NewHeadingRoutine (){
         var floor = $$anonymous$$athf.Clamp(heading - maxHeadingChange, 0, 360);
         var ceil  = $$anonymous$$athf.Clamp(heading + maxHeadingChange, 0, 360);
         heading = Random.Range(floor, ceil);
         targetRotation = new Vector3(0, heading, 0);
     }



try this and ask if you have problem

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

11 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

Related Questions

Monster doesn't move 0 Answers

Move Enemy randomly in a range. 3D 0 Answers

Enemy not rotating when inside range 1 Answer

Enemy following the target with ITween 2 Answers

Enemy Follow Script Help 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