AI to make an object wander around and avoid obstacles?

Hello,

I am not asking anyone to write me a script or anything just some sort or pointer or direction to head in. I want to make a script that I would be able to attach to an enemy or something to make it wander or meander around aimlessly and randomly while also avoiding collisions with other objects. Any ideas that I may be able to investigate? Thank you.

A* might be a good place to start looking: http://www.arongranberg.com/unity/a-pathfinding/

You can use UnitySteer. See the examples.

In order to make it walk around you'd need to basically do 3 things:

1) Pick a random direction (check out Random.insideUnitCircle in scripting help is a good start if its only 2D movement you are after)

2) Send out a ray in that direction, starting from the object and see if it hit anything (check out Collider.Raycast or Physics.Raycast)

3) If the ray did not hit anything, or if it hit something but it is within the acceptable distance away from the object then add some Force to it (if using a Rigidbody component) or lerp the objects transform (iTween or something would help here)

After you made that function you would just randomly call, or call it at an interval to have it meander in different directions. (InvokeRepeating)

RAIN is a, free, complete solution for adding pathfinding, movement, sensing, and behavior to Unity projects.

We have a lot of support resources to help you create characters that drive your story’s narrative. http://bit.ly/1bczozr

Email me jester@rivaltheory.com if you have any questions.

So I have been trying to work out a basic little code to make it wander, (without avoiding collisions yet) but it doesn't seem to be working. This is the code I have worked out so far.

var speed : int= 5;
var wayPoint : Vector2;

function Start()
{
InvokeRepeating("Wander", 2, 20);
}

function Wander()
{
var wayPoint : Vector2= Random.insideUnitCircle *47;
Debug.Log(wayPoint);
}

function Update()
{
transform.LookAt(wayPoint);