AI Detecting Object (Raycast)

Hi again!

I’m still working on trying to get my AI to get around object around the map without running through them. What I need is for my AI to send out rays in the 180 degree radius in front of him. And if one of those rays hit an object that is say 50 units away from him…He will rotate little by little until that ray isn’t hitting anything again. This would be very helpful for my AI when he is chasing my player around and my player runs behide a wall. Also when the AI is just wondering around freely…What I have so far is one ray sent out in front of the AI that picks up objects up to 50 units away…I don’t know where to go from there on rotating the AI or sending out more then just one ray…The script is below and if anyone needs any other script to help salve this problem just ask and I would be happy to get it to them…Any help would be greatly appreshated!!! Thanks!!!

function Update () {

var fwd = transform.TransformDirection (Vector3.forward);

if (Physics.Raycast (transform.position, fwd, 50)) {

print ("There is something in front of the object!");  
}
}

See My Comments =]

Have you considered using either UnitySteer or if you have Pro, using the built-in pathfinding in 3.5?

i wouldnt set the Raycast to 180 degrees, otherwise it might be hard to get through small gaps

i think the suggested code above will also have problems with small gaps and also if the enemy and the player create a line that is exactly perpendicular to a wall (the enemy will actually run straight away from you). Good for small objects though.