var Player : Transform;
var damp = 2;
var velocidadePerseguidor = 4;
function Update(){
if(Player!=null){
if(Vector3.Distance(Player.position,transform.position) < 20){
var rotate = Quaternion.LookRotation(Player.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotate,damp * Time.deltaTime);
transform.Translate(0,0, velocidadePerseguidor * Time.deltaTime);
}
if(Vector3.Distance(Player.position,transform.position) < 2){
Destroy(Player.gameObject);
animation.wrapMode =WrapMode.Once;
}
}
}
But he just follows the player if his name is “Player” and when I connect a new player, they are omeados of “Player (Clone)”
Does anyone have any suggestions so that he can follow every player
var Player : Transform;
// ...
{
Player = GameObject.FindWithTag("Player"); // Use FindWithTag() Instead of FindGameObjectsWithTag(). The 2nd finds every GameObject with Tag, so there might be a problem. If you want the AI to follow the nearest player, you'll have to create a function to calculate the distance and those. The distance function is Vector3.Distance
}
It’s only a matter of assigning the transform. Obviously 1 instance can not follow 2 players so you’ll have to have 2 instances or the amount of players.
Well … It works a bit.
Except that when I instancializo a new player, “Player (Clone)”, it does not work!
But if I drag and place the player on the scene and run it, it works!