- Home /
This post has been wikified, any user with enough reputation can edit it.
enemy does not follow the player
here is my script that,
var Player : Transform;
var ChaseSpeed = 1.0;
var RotateAroundSpeed = 20;
var timeToChange: float = 0;
var minTime: float = 1; // min time to revert direction
var maxTime: float = 5; // max time to revert direction
private var direction: float = 1;
function Update (){
DetectDistance ();
}
function DetectDistance () {
var dist = Vector3.Distance(Player.position, transform.position);
Debug.Log ("Distance to player: " + dist);
if(dist <= 3.5){
RotateAroundPlayer();
} else {
ChasePlayer ();
}
}
function ChasePlayer () {
transform.position = Vector3.Lerp(transform.position, Player.position, Time.deltaTime / ChaseSpeed);
}
function RotateAroundPlayer () {
if (Time.time > timeToChange){
timeToChange = Time.time + Random.Range(minTime, maxTime);
direction = -direction;
}
var Rotate_Speed = Random.Range(1,RotateAroundSpeed);
transform.RotateAround (Player.position, Vector3.up, direction * Rotate_Speed * Time.deltaTime);
}
enemy does not follow and the player when the player get closer to the enemy. First I occured the script code and slipped it into enemy prefab, then choosed player as target. the steps are all but ı could not get anythıng about it. could you please help me. thanks.
Comment
Your answer
Follow this Question
Related Questions
Navmesh follow and stop at a distance 2 Answers
Enemys following and shooting 1 Answer
make enemy attack 0 Answers
AI Following Problem 1 Answer
Enemy reorienting for player 1 Answer