Quantcast
Channel: Answers for "How can i detect collision in melee combat?"
Viewing all articles
Browse latest Browse all 4

Answer by bigbat

$
0
0
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().currentstate==SimpleAI.aistate.ais_attack) { dmg=GetComponent().DamageRank; if(collision.gameObject.tag!="Player") collision.gameObject.GetComponent().SetAIHealth(- dmg,0) ; else collision.gameObject.GetComponent().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"); } } }

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images