Raycasting Help

The problem i have is the AI should look at the player then when it hits a object with the tag Prop stop looking at the player and rotate then wait and look at the player again. This is my first attamp at AI and Raycasting so i am in a bit over my head i understand the logic of it but cant seem to get it coded correctly. I hope someone can help with this and if you do thanks :slight_smile:

here is the code

var target : Transform;
var robotController : CharacterController;
var speed : float = 20.5;
var backwardsSpeed : float =-20.5;
var rayLength : float;
var lookAtPlayerTime : float;
function Start()
{
	target = GameObject.Find("MadDoc").GetComponent(Transform);
	robotController = GetComponent("CharacterController");
}

function Update()
{

	
	var dir = transform.TransformDirection(Vector3.forward);
	var dirleft = transform.TransformDirection(Vector3.left);
	var dirright = transform.TransformDirection(Vector3.right);
    var hit : RaycastHit;
    Debug.DrawRay(transform.position, dir * rayLength, Color.black);
    Debug.DrawRay(transform.position, dirleft * rayLength, Color.black);
    Debug.DrawRay(transform.position, dirleft * rayLength, Color.black);

    if(!Physics.Raycast(transform.position, dir, hit, rayLength))
       {
       		if(hit.collider.gameObject.tag == "Prop")
       		{
       			transform.Rotate(0,30 * Time.deltaTime,0);
       			var forward1 : Vector3 = transform.TransformDirection(Vector3.forward);
				var curSpeed1 : float = speed * Time.deltaTime;
				robotController.SimpleMove(forward1 * curSpeed1);
       		}
       		
       }
       else 
       {	
       		var forward : Vector3 = transform.TransformDirection(Vector3.forward);
			var curSpeed : float = speed * Time.deltaTime;
			robotController.SimpleMove(forward * curSpeed);	
			LookAtPlayer();
       }
       
     

         
}
function LookAtPlayer()
{	
	yield WaitForSeconds(lookAtPlayerTime);
	transform.LookAt(target);
}

From your comment your problem is how to smoothly look at a target. For that you can gradually update the rotation every frame, e.g. using Quaternion.Slerp:

// do this every update/iteration while in the "look at target" state:
var rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, 
                                     Time.deltaTime * speed);

Thankyou gfr i will try this right now thanks mate very much