|
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?
(comments are locked)
|
|
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!) To get something a little less regular than sin and cos, Perlin noise could be used instead. See http://unity3d.com/support/resources/example-projects/procedural-examples
Dec 22 '09 at 09:36 AM
runevision ♦♦
(comments are locked)
|
|
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.
(comments are locked)
|

Thanks for the answers and I'm sorry I haven't responded, my initial enemy code has yet to be at a stable enough state to test these out. Once I get one going I'll post the results back here.
Enemies and hazard objects still... not... there... but, these answers haven't been forgotten!