- Home /
MoveTowards not moving towards! lol.
Can someone do a check on this and see if this works on their end? It seems right to me, and the strange part is that the print statement is firing off every time the while statement loops, yet the object "tractor" will not move!
function StartTractor ()
{
//find the z value by searching through spawner array and comparring y value
var findZ: float;
for (var spawner : Transform in alienSpawnPoints)
{
if (spawner.localPosition.y == targetObjectRow)
{
findZ = spawner.position.z;
}
}
// sets up the starting position for tractor
var startPosition = Vector3(-8.6, targetObjectRow, findZ);
var endPosition = Vector3(9.6, targetObjectRow, findZ);
var step = 5;
Instantiate (tractor, startPosition, Quaternion.identity);
while (tractor.transform.position != endPosition)
{
tractor.transform.position = Vector3.MoveTowards(tractor.transform.position, endPosition, step * Time.deltaTime);
print ("in here");
yield;
}
Destroy(tractor);
}
Anyone have any theories why the print fires off, yet the object will not move to it's end goal?
I've checked and rechecked. startPosition is (-8.6, 2.1, 5.0) endPosition is ( 9.6, 2.1, 5.0). So it really should be simply travelling a straight line to get from start to end. This blows my brain!
Why would it move towards lol?
(Hint, "loling" at yourself in your messages is very unprofessional. It reads like a child wrote it. Even if you ARE a child, you don't want to read that way.)
Jeff, let's take a step back here and look at this whole picture;
You have just posted in a question, that had already been answered, to insult the person asking the question...
While at the same time, offering no insight regarding the question.
Think about that, and then ask yourself, who comes across as a "child"?
Answer by rutter · May 22, 2014 at 10:07 PM
You may want two separate variables: tractor
and tractorPrefab
.
tractor = Instantiate(tractorPrefab, startPosition, Quaternion.identity);
Point being, Instantiate
returns a reference to the clone. Since you don't save that reference anywhere, you effectively lose track of the newly cloned tractor just as soon as you create it.
Holy mary mother of god. That worked instantly. I would never have figured that out. $$anonymous$$ake sense though, now that I think about it.
thanks rutter!
Your answer
Follow this Question
Related Questions
How to set a target position in Vector3.MoveTowards using a variable 2 Answers
spawn objects in random locations, check if location already taken 1 Answer
[SOLVED] Coroutine while loop exits before condition met 1 Answer
Unsure why I am getting errors 1 Answer
How to make an object move towards an object at a constant pace, no matter how fast the object is? 0 Answers