- Home /
Obects following in order
I'm currently trying to find a way to spawn an object and make it follow a certain object, and when it spawns another one, it will follow that was spawned before it, I have the following part down in JScrpt, but what would I use for changing the targets of the following script?
Answer by Berenger · Jan 28, 2012 at 07:39 PM
The script that spawn your objects must remember the last one, so it can give to the next. I'm afraid your script isn't visible.
Answer by Nyath · Jan 28, 2012 at 08:18 PM
Sorry about that, I was waiting for my question to become visable.`var target : Transform; var movespeed; var rotationspeed = 3; var ms =3; var myTransform : Transform;
function Awake () { myTransform = transform; }
function Update () { var other : Transform; var dist = Vector3.Distance(target.position, myTransform.position);
if (dist <1) { movespeed = 0; } if (dist >1) { movespeed =ms; }
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationspeed*Time.deltaTime);
myTransform.position += myTransform.forward * movespeed * Time.deltaTime;
}
//
//function Start() //{ // target = GameObject.FindWithTag("Player").transform;
//}
`,var target : Transform; var movespeed; var rotationspeed = 3; var ms =3; var myTransform : Transform;
function Awake () { myTransform = transform; }
function Update () { var other : Transform; var dist = Vector3.Distance(target.position, myTransform.position);
if (dist <1) { movespeed = 0; } if (dist >1) { movespeed =ms; }
myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
Quaternion.LookRotation(target.position - myTransform.position), rotationspeed*Time.deltaTime);
myTransform.position += myTransform.forward * movespeed * Time.deltaTime;
}
//
//function Start() //{ // target = GameObject.FindWithTag("Player").transform;
//}