- Home /
Can't properly duplicate an enemy AI
Hello! I'm currently making a 3D combat action game. So far i've done the movement,the minimap, a map and also an enemy ai. Now that I finished a map I want to duplicate the ,,Skeleton" AI to put him into more parts of the map. However, when I do so, when I hit play only one shows up on the screen, the rest dissapear. How can I fix this? The enemy AI has 2 scripts attached to it: the target script which determines the health the enemy has and the ChasePlayer script which tells him to chase the player if it's in range (Look at the pictures below for the full details). What is wrong? Thanks and sorry for my bad english!
CHASE PLAYER SCRIPT:
public PlayerHealth script; this gets the player health from another script
Transform player;
static Animator anim;
void Start()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
Vector3 direction = player.position - this.transform.position;
float angle = Vector3.Angle(direction, this.transform.forward);
if (Vector3.Distance(player.position, this.transform.position) < 10 && angle < 60)
{
direction.y = 0;
this.transform.rotation = Quaternion.Slerp(this.transform.rotation,
Quaternion.LookRotation(direction), 0.1f);
anim.SetBool("isIdle", false);
if (direction.magnitude > 2)
{
this.transform.Translate(0, 0, 0.05f);
anim.SetBool("isWalking", true);
anim.SetBool("isAttacking", false);
}
else
{
script.TakePlayerDamage(0.3f);
anim.SetBool("isAttacking", true);
anim.SetBool("isWalking", false);
}
}
else
{
anim.SetBool("isIdle", true);
anim.SetBool("isWalking", false);
anim.SetBool("isAttacking", false);
}
}
TARGET SCRIPT:
public float startHealth = 50f;
private float health;
public Image healthBar;
public GameObject destroyedVersion;
void Start()
{
health = startHealth;
}
public void TakeDamage (float amount)
{
health -= amount;
healthBar.fillAmount = health / startHealth;
if (health <= 0f)
{
Die();
}
}
void Die()
{
Instantiate(destroyedVersion, transform.position, transform.rotation);
Destroy(gameObject);
}
Your answer
Follow this Question
Related Questions
Raycasting AI 0 Answers
Enemy keeps moving in one direction. Help pls! 2 Answers
Distribute terrain in zones 3 Answers
Enemy AI Not Working? 0 Answers
If I duplicate enemies, will their scripts mess each other up? 2 Answers