I want a pawn to see my player

I’m trying to get a gameObject to see my player, and follow him if he does(Simple AI). I’m thinking of using a rayTrace, but I’m not sure how to use that. Can I use instantiate or something? I’m a noob to Unity but come from UnrealScript.

You are right to think about a ray, but in Unity it is a RayCast (in the docs, if you searched on “ray” you would have found it).

I tought of this ideea, you make an emptygameobject, and name it dummy, parent it to the pawn, and we make that dummy always look at the player so we know the direction of the raycast (which will be dummy.transform’s z-axis). then we check to see if the distance form the pawn to its target (which is the player) is lesser than the maxFollowingEnableDistance, he casts a ray in the direction of the player, if that ray hit the player, it will return in hit.rigidbody the rigidbody info of the player, you check the name, and if the name is equal to “playerName” you start the following script. Look here to understand more about the raycast: Unity - Scripting API: Physics.Raycast

UNTESTED CODE:

public class example : MonoBehaviour {
    void Update() {
        RaycastHit hit;
		dummy.transform.LookAt(target.transform.position);
		if(Vector3.Distance(transform.position, target.transform.position) < maxFollowingEnableDistantce){
	        if (Physics.Raycast(dummytransform.position, dummy.transform.forward, out hit)){
	            if(hit.rigidbody.name == "Player"){
					//start following script
				}
			}
		}
    }
}

PS: i am new to unity myself, and this might not be the best ideea, but it’s a starting point.

Thanks, guys. It’s really close to what I want. I got a capsule to follow the player no matter where he goes. I can build from this.

P.S. I’m loving Unity, especially since I’m scripting better, it F-ing rocks.