Hello! I’m developing a fps game in which i have a player model and a zombie model.
for some reasons the enemy model just keeps bumping or entering into my player model rather than attacking.
I have set the enemy trigger on the fps controller and also made a collider trigger which has the script of Enemy AI to walk towards the player when in range and stay idle when out of range. The main zombie model is the child of this box collider of the zombie.
what is the issue? is this something regarding the attack script or triggers or the child and parent of zombie thing?
Please help me out in this issue. if possible please suggest me some solutions in my script, all the animations are marked as legacy. Do i need to change parent or child of zombie model?
I have attached my script for the zombie AI and also the Screenshots of zombie anims and parent/child.
.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ZombieEnemy : MonoBehaviour
{
public GameObject ThePlayer;
public float TargetDistance;
public float AllowedRange = 10;
public GameObject TheEnemy;
public float EnemySpeed;
public int AttackTrigger;
public RaycastHit Shot;
void Update()
{
transform.LookAt(ThePlayer.transform);
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out Shot))
{
TargetDistance = Shot.distance;
if (TargetDistance < AllowedRange)
{
EnemySpeed = 0.05f;
if (AttackTrigger == 0) ;
TheEnemy.GetComponent<Animation>().Play("walk");
transform.position = Vector3.MoveTowards(transform.position, ThePlayer.transform.position, EnemySpeed);
}
}
else
{
EnemySpeed = 0;
TheEnemy.GetComponent<Animation>().Play("idle");
}
if (AttackTrigger == 1)
{
EnemySpeed = 0;
TheEnemy.GetComponent<Animation>().Play("attack");
}
}
public void OnTriggerEnter()
{
AttackTrigger = 1;
}
public void OnTriggerExit()
{
AttackTrigger = 0;
}
}