helping with script (AI)

Hi ALL! =)
Can you help me?
i recently using this product and i have some problems with script…
i complete some script of ENEMY
and i don’t know how to do chase effect… =(

var turnSpeed : float = 5;
var speed : float = 10;
var distanceToGo : float =5;
var leftOrRight :boolean = true;
var player : Transform;

function Update () {
	if(Input.GetKeyDown(KeyCode.E)){
		if(leftOrRight)
			leftOrRight = false;
		else
			leftOrRight = true;
	}

var hit : RaycastHit;
var fwd : Vector3 = transform.forward;

if(Physics.Raycast(transform.position, fwd, hit, distanceToGo)){
	if(leftOrRight)
		transform.Rotate(Vector3.up, 90 * turnSpeed * Time.smoothDeltaTime);
	else
		transform.Rotate(Vector3.up, -90 * turnSpeed * Time.smoothDeltaTime);
		
}
else{
	transform.Translate(Vector3.forward * speed * Time.smoothDeltaTime);
	}

}

thanks)

I am a bit confused, your code has nothing to do with chasing, it looks like obstacle avoidance.

In your script, you need to first do a Linecast from the person to the target, if there is something in the way, then you need to work on obstacle avoidance. For what you have, you really need to fulfill the leftOrRight variable with a Vector3.Dot to the other player for the right side. This will get you a bit more in the ball park.

well…this is clear script (because you may confusing)
but i can give to you script with chase…but i can’t merge 2 scripts with waypoints…and without… =(

this is my “homework”

and with waypoints + chasing)

how i can merge?

In doing AI, I usually use an empty gameObject called target. (usually I make a cube and turn the meshfilter off so that I can debug if I need to later.) The first thing I do when moving to a waypoint, or an enemy is to check to see if the unit can see the waypoint or enemy. Then I make a decision if I want to go after that target, or choose another.

So look at it start to finish:

If we can see an enemy/waypoint update the target to be on the waypoint.
If we cannot see our enemy/waypoint:

leave the target at the last known enemy position (if we are following an enemy, this is a neat way to breach a corner.)
If we are working on a waypoint then choose a new target or choose to wait.

If we have lost our enemy, then we need to move to the closest waypoint on our path that we can see.

If we choose a new waypoint, it HAS to be a waypoint we can see. if not, we choose a random point and wander to it or wait

if we wait then waiting is nothing but wait until a new time, or until we see a new enemy, whichever comes first.

By now, we know if we are moving, and where to… Now we do our moves. Any obstacle avoidance can be done here.

aaaah) okay…i will try =)
i told you when i done this)