Hi all,
At the moment I have a script called Follow.js, which is applied to multiple cubes. What happens is that when you hit a cube, it starts to follow you and then when it gets within two blocks of you it stops…this is working fine. But what is happening is when i stop all of the cubes following me merge into one, how would i do it so that they do not clip inside each other, and stay in their stationary positions behind me?
Follow.js:
var target : Transform; //the enemy's target
var moveSpeed = 3; //move speed
var rotationSpeed = 3; //speed of turning
var Player = GameObject.Find("Player").transform.position;
var Cube2 = GameObject.Find("Cube2").transform.position;
var myTransform : Transform; //current transform data of this enemy
function Update () {
if (target == GameObject.FindWithTag("Player").transform)
{
//rotate to look at the player
//GameObject.Find("Cube2").transform.position = GameObject.Find("Player").transform.position + 5;
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime);
var distanceToPlayer : float = Vector3.Distance(target.transform.position, myTransform.position);
if(distanceToPlayer > 2){
//move towards the player
myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
}
}
}
Thanks for any suggestions!