Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
V3ndetta

How to loop this correctly?

Question

I have made an AI wandering script, that moves the sprite to a random X position  from inside a range, and when it has got to it's destination, chose a new random X position to go to. The problem is, the sprite sometimes is shaking like possessed for a very little time while or before moving on. It may be a problem of calling the coroutine in the Update function, but without that the sprite won't move because using

Please login or register to see this code.

. Maybe I need to split my coroutine in 1 more function to handle it?

Please login or register to see this code.

 

Edited by V3ndetta

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 1

Add a Boolean to determine its current state. So put isYielding = true before your return new wait for seconds. Then after put isYielding = false. Then in the update function put if(!isYielding) StartCoroutine(doWander);

Share this post


Link to post
Share on other sites

  • 0
Please login or register to see this quote.

 

I guess the problem of shaking was caused by 2 or more values being created and "overlapping". Many thanks now I know how to loop functions after they are finished!

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...