In my game i have two group of ai characters(i.e. red and blue)and red ai could attack to blue’s.my npc’s have a “charactercontroler” component and their attack animation is melee type such as punching or Spurn attack without any weapon.Since my npc’s collider is a capsule like(charactercontroler)and their hand or leg dose not had collider,how can i detect colliding with other npc’s?
I try adding a separate collider(capsule collider) to their hand and leg,but it did’nt work.
any suggestion or help would be appreciated.
excuse me for my bad english.
For future readers:
I add some empty gameobject to npc’s hand and foot and added capsule Collider’s to them and use oncollisionEnter for detecting collisions and modify npc health.
For solving weird npc movement i enable all X, Y and Z parameters of Freeze Position and Freeze Rotation in Constraints of rigidbodies(i leave “IsKinematic” and “use gravity” fields unchecked).
here is my collision detection script:
void OnCollisionEnter(Collision collision)
{
int dmg;
if(collision.gameObject.layer!=gameObject.layer&&collision.gameObject.layer!=0)
{
if(GetComponent<SimpleAI>().currentstate==SimpleAI.aistate.ais_attack)
{
dmg=GetComponent<AIHealth>().DamageRank;
if(collision.gameObject.tag!="Player")
collision.gameObject.GetComponent<AIHealth>().SetAIHealth(- dmg,0) ;
else
collision.gameObject.GetComponent<playerstatus>().SetPlayerStatus(-dmg,0);
Debug.Log(collision.gameObject.name+ " is damaged by "+name+" by damage "+dmg+"time:"+Time.time);
}else
{
Debug.Log(gameObject.name+"collided with: "+collision.gameObject.name+" and not attacking");
}
}
}