Hello, and thanks in advance for you consideration.
I have rigid body game objects that are going to be pathing to defined triggers "goals" in the world. I'm probably going to use constant force on them to move them as I have to pay the price of having them as rigid bodies anyways.
I think I can figure out how to set the constant force to get them straight to their goals but I'd like them to loop and veer on the way there, kinda like a really drunk guy walking down the middle of the street. I don't need traditional pathfinding since there will be nothing in the way they need to navigate around.
EDIT: FYI the goals may be moving, not very far, but at varying speeds.
Can anyone suggest a method for doing this?
Whichever way you do this, you probably want to use a gradually changing set of values rather than affecting the movement by random numbers each frame, as this will usually result in random jittery movement as opposed to smooth loops and curls. Both my examples below use the Sin function to give this kind of smoothly changing movement.
Also I'm assuming you only want to modulate the movement in the x-z plane as is usual with many games.
One way you could approach this is to modulate the target position that your 'drunk guy' is heading for. For example, in FixedUpdate, you could calculate a dummy target position which is offset from your real target position by an amount proportional to the current distance from the target. This will give you quite a uniform left-to-right swerving which reduces as it approaches the target.
1 - A hidden dummy object which moves straight for the target, as you've suggested that you can already do (if you want to use forces, this could be a rigidbody with no collider or renderer). We'll call this the 'seeker'.
2 - A separate 'drunk guy' rigidbody which is visible, which always heads for a point which is offset from the 'seeker' object by a varying amount.
For example, on the 'drunk guy' object, you would have something like this:
(these are illustrative untested code snippets. if you encounter errors, please leave a comment and I'll fix them!)
answered Dec 22 '09 at 07:58 AM
You could apply a random force that diminishes as he gets closer.
Just multiply your random force by that. Of course, you'll need to define MAX_FORCE and FORCE_RATIO.
answered Dec 22 '09 at 02:02 AM