how to check? `while(Vector3.Distance(yourMonsterName.transform,transform.position) > 2)`
-
rotate + move
var rotationSpeed : float = 0.2;
var direction : Vector3 = transform.position - yourMonsterName.position;
while(Vector3.Distance(yourMonsterName.position,transform.position) > 2)
{
transform.rotation = Quaternion.Slerp(transform.position,Quaternion.LookAt(direction), rotationSpeed* Time.deltaTime);
transform.eulerAngles = new Vector3(0,transform.eulerAngles,0);
yield;
<pre>`}
`
it was above how to rotate, now how to move?
while(Vector3.Distance(yourMonsterName.position, transform.position) > 2){
//animation.CrossFade("walk"); //if u have animation @walk
var controller : CharacterController = GetComponent(CharacterController); // reference the CharacterController to controller
var direction : Vector3 = transform.position - yourMonsterName.position;
controller.SimpleMove(direction.normalized * speed);
yield;
}
Also , I'm not but this: `var direction : Vector3 = transform.position - yourMonsterName.position`; can be changed to this: `var direction : Vector3 = yourMonsterName.position - transform.position;`
- add this script to ur enemy (it must have character controller though)
http://09duck.pastebin.com/2DCZXt4M
open the waypoint slot in the monster's inspector and add 3 waypoints gameobjects to it.
so u may ask how to create a way point and recognize it in inspector?
so paint a simple circle in ur Paint program and it to unity's project, open a folder called "Gizmos" it's case sensitive btw! so make it as written in quotation marks,add the picture to it, make sure u saved the picture as jpeg/jpg format! and make sure the
picture is called "waypoint"!
add this script to ur waypoint gameobject : http://09duck.pastebin.com/LYpj7aLW
so now u'll see ur waypoint with a picture, now u can attach all ur 2,3,4,5,6 or how many u want to ur waypoint. the script is designed to work on 3 waypoint, but u can simple make it 4,5,6,7 by changing this line :
if(currentWaypoint == 3){ currentWaypoint -= 3; }
to like:
if(currentWaypoint == 5){ currentWaypoint -= 5; }
which means 5 waypoints, when it reaches the 5th it goes to the first one.