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
0
Question by questioner · Jul 31, 2013 at 12:14 AM · collisionrigidbodycolliderweaponmelee

Colliding Melee Weapons

What would the setup look like (RigidBody, Collider, IsKinematic? Constraints? IsTrigger?) to have two melee weapons colliding?

I would like the translation/rotation of the weapon to be determined by the animation (hand), but if it collides with another weapon (shield) should stop or even add a force to the opposing weapon. Also if it hits the character's collider give out damage.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by danivdwerf · Aug 18, 2016 at 10:20 AM

He, I don't know if you are still having troubles, but I fixed mine.

You can just put a collider on your weapon that follows your weapon. than you can check with a collision or trigger enter with the player(or enemy). If you do that, it will also do damage if you just walk by and accidentally walk to close to the collider.

put this as a variable


private int _playerAttackStateHash = Animator.StringToHash("Base Layer.Attack");
//Base layer is the default layer the animation will be played on, if you have multiple layers, you want to change it. the Attack is the name of your animation on the layer(name it excact the same).

now you can only do damage if: the weapon hits you AND he's is playing his attacking animation


void OnTriggerEnter(Collider other)
{
    if (other.CompareTag("Player"))
    {
        //Checks if attack animation is playing
        AnimatorStateInfo info = _animator.GetCurrentAnimatorStateInfo(0);
        if (info.nameHash == _playerAttackStateHash)
        {
            //Do Damgae;
        }
    } 
}

but what if your animation makes the weapon hit the player or enemy BEFORE it should do damage?? Then you can put animation events in your animations, so you can only do damage between certain frames of the animation.

put a script on the same object as your animator, and make a pulic function with one integer parameter. Also make a public int and in the function, set that value to the parameter.

click on the attacking gameobject with the animation on it. in the inspector, go to animations and open the tab events. on the frame you want put an event and at function you fill in your function name. In the int slot, you fill in one. put another event on the frame you want to stop dealing damage and do the same, but fill a 0 in this time. Now you can only do damage if: the weapon touches you AND the attack animation is playing AND if you are actually hitting in the animation.


    void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            //Checks if attack animation is playing
            AnimatorStateInfo info = _animator.GetCurrentAnimatorStateInfo(0);
            if (info.nameHash == _playerAttackStateHash)
            {
                //checks if the animation Event gave through the number I set up
                if (ANIMATORSCRIPT.INTEGER == 1)
                {
                    PlayerHealth.health.Hurt(30);
                }
            }
        }
    }

good luck with your ganme

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 Nevadaes · Jul 31, 2013 at 12:41 PM

You can attach a box collider or even a mesh collider directly to the weapon / shield GameObject, so that, whenever your hand animation moves it, the collider will move and rotate along. You can then add collision callbacks for those two type of objects only, so that you can manage weapon collisions.

Afterwards, the choice is yours: you can either trigger an animation upon collision, use kinematics so that animation continues but that the weapon looks effectively stopped, etc.

Comment
Add comment · Show 2 · 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 questioner · Jul 31, 2013 at 05:23 PM 0
Share

Thanks for the reply, but won't two Is$$anonymous$$inematics pass through one another?

avatar image danivdwerf · Aug 09, 2016 at 02:27 PM 0
Share

A problem you will have then (and which I'm struggling with right now) is, the weapon does always damage if you hit it. you can check collison only when attacking, but it still may do damage when you don't want to

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

16 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

Related Questions

My Character controller is being push a little bit when i'm about the get the coins. How can i possibly detect collision and destroy the coins without actually getting affected by the colliding physics? 1 Answer

Objects with colliders going through walls and each other. 3 Answers

Collider going through walls with box collider.. 1 Answer

Rigidbody colliders 1 Answer

GameObject ignores collision while swinging from hinge joint 2D 4 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