Raycast - enemy does not look forward but into the same point ...

I have no idea why the emeny sends raycast into the same targetPosition …

here is the code :

    //Send raycast to imitate enemy sight
void SendRaycast() {
	//Start and end point of raycasts
	Vector3 startPosition = transform.position;
	Vector3 targetPosition = Vector3.zero;

	//Start and end angle of raycasts
	int startAngle = (int)(-angle * 0.5F);  // half the angle to the Left of the forward
	int finishAngle = (int)(angle * 0.5F); // ..... and to the Right

	int inc = (int)( angle / 10 );

	//raycast that we are going to 'send'
	RaycastHit hit;

	// step through and find each target point
	for(int i = startAngle; i < finishAngle; i += inc ) // Angle from forward
		targetPosition = (Quaternion.Euler( 0, i, 0 ) * transform.forward ).normalized * 5.0f;
		//targetPosition = transform.forward;

		// linecast between points
		if ( Physics.Linecast( startPosition, targetPosition, out hit ) )
			if(hit.collider.gameObject.tag == "Player") {
				chase = true;
				Debug.Log("See Player");
		// to show ray just for testing
		Debug.DrawLine( startPosition, targetPosition, Color.green );

A LineCast() takes two positions. You are supply it with a position and a direction. I believe you want a Raycast instead, which does take a position and a direction.

   if ( Physics.Raycast( startPosition, targetPosition, out hit ) )

In the unlikely event you really do want a Linecast(), you’d have to decide on a distance in front. Then you could add just before the Linecast:

targetPosition = startPosition + targetPosition * someDistance;

I have something an old project of mine, where the enemy was facing the player and later chased him. Here’s what I used for the enemy to smoothly turn at the target and face him:

var target : Transform;
var damp = 6.0;

function lookAtTarget() {
	var rotation = Quaternion.LookRotation(target.position - transform.position);
	transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damp); //turn smoothly

It’s JS though. Hope it helps.