I have a sprite which has Velocity
and Position
, either stored as Vector2
. At each Update
cycle, velocity is added to the position.
I would like to give the sprite a third vector, Target
. New targets may be given at any iteration. I would like the sprite to essentially move in a random walk pattern, however two parameters must be exposed:
- A typical random walk is equally likely to increase or decrease the distance to any given
Target
(plus the small chance of tangential movement). I must be able to bias my random walk such that, while still random, the direction on which the sprite "decides" should be more likely to bring it closer toTarget
. - The random walk should be "smooth"- the sprite should not rapidly change direction, as this will look like it's "flickering" or "trembling" to the player. It should gradually veer this way or that, moving randomly, while slowly getting closer when averaged.
What is a good, simple way to do this? If possible, give the answer as a Vector2 RandomWalk(Vector2 target)
method.
I already have a NextGaussian(mean, stdev)
method available, if that is helpful.
Answer
I would take the "wander" steering-behavior (source code can be found here) and tweak it in a way so that the random numbers are biased towards your target.
No comments:
Post a Comment