Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by bigbat · Jun 29, 2013 at 09:09 PM · collisioncollidermeleecombat

How can i detect collision in melee combat?

Hi to all

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.

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bigbat · Jun 30, 2013 at 02:19 PM 0
Share

No one can help!?forum masters!!

avatar image Kaivo · Jun 30, 2013 at 02:27 PM 0
Share

Similar questions that could help: http://answers.unity3d.com/questions/37093/recommended-approach-for-melee-combat-system.html

http://answers.unity3d.com/questions/193996/melee-combat.html

http://answers.unity3d.com/questions/160747/ontriggerenter-melee-combat.html

http://answers.unity3d.com/questions/63009/what-is-the-best-way-to-do-third-person-melee-comb.html

avatar image bigbat · Jul 01, 2013 at 11:38 AM 0
Share

Excuse me for late reply. i get look at first link and it was helpful. I add some empty gameobject to npc's hand and foot and added capsule Collider's to them and used oncollisionEnter for detecting collisions and modify npc health,but a weird thing happened.It seems body part Colliers (hand and foot) collide eachother and it cause in function ,same object destroy itself Is it possible?

avatar image Kaivo · Jul 01, 2013 at 12:05 PM 0
Share

@bigbat it is possible. To avoid this, in your OnCollisionEnter function, add a check for a specific tag so that you can check the collider object and only perform the function on the right objects.

 void OnCollisionEnter(Collision collision) 
 {
     if(collision.transform.tag == "WhatImLookingFor")
     {
         // bla bla bla
     }
 }
avatar image bigbat · Jul 01, 2013 at 05:06 PM 0
Share

@$$anonymous$$avio thanks for advice. Now i have another issue,as explained in unity documentation for colliding i add rigidbody to my npc's,but my npc's start moving in world with very high speed and unexpected movement(for clarification:my npc's use unity Nav$$anonymous$$esh and Nav$$anonymous$$eshAgent for moving in game world,and i dont use any physic related movement such as addforce ,and before i add rigidbody to them they act correctly and all things was ok). if i check "is$$anonymous$$inematic" field of rigidbody, the problem of movement resolve but else again no collision occure between npc's. whats wrong in my setup? thanks for your time and help.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by bigbat · Jul 05, 2013 at 06:45 PM

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");
         }
     }
     }
 
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Slobdell · Jun 30, 2013 at 08:06 PM

Well why don't you just add more colliders?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Melee attack comblat 1 Answer

Melee Combat 1 Answer

Multiple Melee Weapons 2 Answers

Colliding Melee Weapons 2 Answers

Sword Combat System: Detect if player in range 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges