- Home /
Question by
madmike6537 · Dec 05, 2012 at 03:19 AM ·
ienumeratortransform.translate
Start and stop movement - question
Trying to find the best way to start and stop an enemies movement, I am building a wandering script and I want the enemies to move a bit, then stop, then move some more.
here is what I have so far - very basic. But the enemy never stops moving. Thoughts on how I can improve this?
Thanks!
IEnumerator MobMovement()
{
moveMobForward = true;
if(moveMobForward == true)
{
myTransform.Translate(Vector3.forward * mobSpeed * Time.smoothDeltaTime);
yield return new WaitForSeconds(5);
moveMobForward = false;
yield return new WaitForSeconds(1.5f);
}
}
Comment
Hmm cant wrap my head around this - I thought my co-routine would be called more than once, but it seems like its called once then never again. (its called in the update function so I dont get that)
Best Answer
Answer by madmike6537 · Dec 05, 2012 at 03:51 AM
Got it working with this for now - its crude and I will probably update later but its working for what I need for now :)
IEnumerator MobMovement()
{
myTransform.Translate(Vector3.forward * mobSpeed * Time.smoothDeltaTime);
yield return new WaitForSeconds(5);
mobSpeed = 0;
yield return new WaitForSeconds(1.5f);
mobSpeed = 1.5f;
}