- Home /
how do I tell when a object gets to a certain spot
I'm making a building thing that makes stuff and I need it to know when a object gets to a certain spot.
var waitTime = 5;
var Builders : GameObject[];
var col : boolean = false;
var start : boolean = true;
var prefab : Transform;
var called : boolean = false;
function Update ()
{
//trying to tell when it is there then stop it and spawn a object
if(Builders[0].transform.position == Vector3(-2, 0, 0))
{
col = true;
}
if(col == false && start == true)
{
Builders[0].transform.Translate(Vector3.forward * Time.deltaTime / waitTime);
if(called == false)
{
Build();
called = true;
}
}
if(col == true)
{
Instantiate (prefab, Vector3(8, 0, 0), Quaternion.identity);
}
}
function Build()
{
//trying to make it wait until it gets there
while(col == false){
yield;
}
col = true;
called = false;
}
thanks in advance ♣
Answer by jrlowe · Oct 23, 2013 at 02:14 AM
If you know what spot the object is going to go to, which in this case -2,0,0, and plan on moving linearly, which you are, I would interpolate the vector instead of translating it. All you would need is Builders[0].transform.interpolate(TargetVector * Time.deltaTime / waitTime); and it will move it to that spot. Then you dont need any other of the code unless you want to see if it there...Object.transform == TargetVector.transform then its there and do what you need. Hope this helped.
Your answer
Follow this Question
Related Questions
Checking the distance between an instantiated object and an existing object 1 Answer
How to get access to child's objects of instantiated prefab on JS? 1 Answer
Instantiate as a child at position 2 Answers
problem with instance 1 Answer
Help, can't get Grid to instantiate in the center of the screen 0 Answers