- Home /
Finding Distances With Vector3
I'm trying to create a script, so that when the object 'runner' is 500m away, a rigidbody will be added. I've looked through the scipting manual, yet that produces an error, which I cannot solve. Where am I going wrong?
var runner : transform; var closeDistance : float = 500; function Update (){ if (runner) { var dist = Vector3.Distance(runner.position, transform.position); if (dist < closeDistance); if(!dist.gameObject.rigidbody){ dist.gameObject.AddComponent(Rigidbody); }
}
}
Thanks.
Answer by PrimeDerektive · Apr 07, 2011 at 04:53 PM
I'm assuming you really want to be adding the Rigidbody to the runner object. You're attempting to add it to dist, which is a float value; epic fail.
You probably want something like this:
function Update (){
if(runner){
var dist = Vector3.Distance(runner.position, transform.position);
if(dist < closeDistance && !runner.gameObject.rigidbody){
runner.gameObject.AddComponent(Rigidbody);
}
}
}
Your answer
Follow this Question
Related Questions
Get 4 smallest distance 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Vector3 Transform.Position Not Working 2 Answers
distance to variable object 1 Answer