Hi friends i am facing problem in enemy ai scripting i am trying to target my player by moving in its same position while rotating and targeting my player but my enemy is following my player and targeting my requirement is not following player only look at player and target while moving i am using look at target function can any one help me here is my code
public class LookAtPlayer : MonoBehaviour {
public Transform player;
public GameObject enemyProjectilePrefab;
public float timeBetweenShootsMin = 0.5f;
public float timeBetweenShotsMax = 1.0f;
public float nextShoot = 0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
player = GameObject.FindWithTag("player").transform;
transform.LookAt(player);
if(Time.time > nextShoot)
{
nextShoot = Time.time + Random.Range(timeBetweenShootsMin, timeBetweenShotsMax);
Instantiate(enemyProjectilePrefab, transform.position, transform.rotation);
}
}
}
and this is the moving script
public class MoveEnemy : MonoBehaviour {
public float enemySpeed;
public float amountToMove;
public Transform myTransform;
// Use this for initialization
void Start () {
myTransform = transform;
}
// Update is called once per frame
void Update () {
amountToMove = enemySpeed * Time.deltaTime;
myTransform.Translate(Vector3.forward * amountToMove);
}
}
i want to move enemy in z direction with out following my player in x direction
– santosh810666