# Object Avoidance AI

Quick question my peeps, I have been doing my AI and set my small water craft on a path and I have it set to check for a wall or any obstacle in its way by doing a find this object and if the distance is this then avoid, now my problem is doing the avoid bit, what is the best way to do it because I want my object to make a decision on the direction of its own, if that makes sense. Now I am taking my cues from “Programming Game AI by Example” from Mat Buckland, it is an older book but great no the less and I am studying alot of Unity’s scrpts also, but I just need some advice and help on how to do object avoidance. If it doesn’t make sense let me know but any help is appreciated.

The simplest method is to raycast to the right and left at a rather obtuse angle, look for freespace and steer in that direction. There’s a few examples of this on the forums, and even a video I remember seeing recently.

http://vimeo.com/9304844

Here it is.

Beast, thanks man it goes right along with the book and I just wanted to confirm what I was trying to do, are there anymore sites like this one on AI?

I implemented an object avoidance script based off that tutorial… but it acts jittery and I’ve never been able to smooth it out. I understand why its jittery, but I can’t figure out how to correct it.

I actually got mine to work, what is the problem with yours, I had to do some tweaking with my own input but it works great.

Basically exactly what i said, it works fine but when the AI is actually avoiding it looks jittery, almost like its doing the raycast every other frame so the rotation isn’t smooth.

Could you upload a webplayer so I can see if how smooth yours is?

Try checking out the value I’ve marked here as “rotSpeed” inside the rotate part of the script:

``````transform.rotation = Quaternion.Slerp(transform.rotation, rot, Time.deltaTime * rotSpeed);
``````

I found having this value too high causes the transform to rotate back towards it’s target too quickly, making it look jittery.