A forum mod kindly provided me the following code as an example of random walking behaviour:
I'm attaching it temporarily to my NPC GameObjects. Testing it, it works well; the NPCs run around and change direction nicely. However, I found that I needed to increase the project gravity, because those GameObjects weren't responding properly at default settings. So, at -1500 gravity, my NPCs fall around satisfactorily, but - I assume because gravity is used in this code - they're now hyperactive; changing direction a few times per second and basically just bobbling around, instead of 'walking'.
I (naively) thought I could just divide the gravity value within this code to return the behaviour to normal, but that didn't work. How can I retain both the necessary gravity value in my project AND the 'normal' behaviour of this code? Or, is there a way to achieve 'proper' gravity in the scene without cranking it up to such a ridiculous value?
-1500 gravity (guess you mean (0, -1500, 0)) sounds a bit high, that would mean a speed 1.5km per second (if using 1 unit == 1 meter).
If you haven't connected the object that's the ground to the NPC it starts to do this little dance, possibly you didn't see this behaviour earlier because gravity was 0. Currently the code allows only one object as ground and you have to set the ground property for all the NPC's, a better solution that allows more objects function as ground is:
Then create a tag 'ground' and set tag of all floor objects to this tag.
answered Dec 01 '09 at 11:21 PM