- Home /
Prevent random movement allowing movement through obstacles
My predator object in my game scene exhibits random movement. It will rotate on the spot by a random amount and then move forward a random amount. I'm using a raycast to determine whether it should be allowed to move or not (whether there is an obstacle in it's path). I have mountains surrounding the area with mesh colliders attached. They are all tagged as 'obstacle' and I need the most efficient way (there are about 20 of them) to check if the predator would collide with them. I have a Vector3 called targetLine that stores the difference between it's current position and it's target position.
There's no question here. Did you have a technical question?
I understood- how do I stop randomly moving game character from bumping into objects tagged with obstacle.
Answer by MountDoomTeam · Mar 09, 2013 at 08:56 AM
what you can do, is you can use a Vector3.Distance () in the update function,
Get all your objects, loop through them, measure the distance of each 1 to the predator, if you are too close to one of the objects, change the predator movement to a tangent/other direction, make him rotate around the object if you want with rotate around function.
by the way, this is a good thing for movement in games http://en.wikipedia.org/wiki/Brownian_motion and I think this is a code for it http://code.google.com/p/pixelplacement/source/browse/trunk/unity/com/pixelplacement/scripts/Perlin.cs?spec=svn142&r=142