Call a function for next several frames?
I have a moveTowards function that will move toward a position using CharacterController.Move. I want to make it so that if I pass a position, the moveTowards function run for a several frames until the character reaches that position.. since for now if I call the function, it will move/"teleport" a small bit (probably calls the move function one frame?) and that's it. Is there a way for this?
**I'm considering using coroutine but there is no specification on if it runs on all frames :(
Answer by Mikilo · Aug 31, 2015 at 12:48 PM
Hello!
You can use Coroutine or Invoke, or doing it manually.
Like:
private IEnumerator MoveTowards(int n)
{
while (n > 0)
{
// MOVE TOWARD
--n;
yield return null;
}
}
Answer by DevPoG · Aug 31, 2015 at 02:05 PM
I would use the Update() of a CharacterMove component to do that, checking if I'm already at the destination point or if I need to move some more !
What is your Character$$anonymous$$ove? Did you mean CharacterController?
In any cases, Update should be avoided whenever it is possible.
Your answer
Follow this Question
Related Questions
Isometric Movent Issue 0 Answers
i am using a code to make my cube walk with character controller ,but when i play the cube spins. 0 Answers
AddForce in Character Controller problem 0 Answers
Why is my character flying off screen? 0 Answers
Smoother grid based movement using coroutines and lerp 0 Answers