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 Pat · Dec 07, 2010 at 07:13 AM · collisionmeleefighting

Recommended approach for melee combat system

I'm developing a melee combat system and I'm wondering if anyone has any suggestions or best practices for how to determine hits and blocks.

Is the use of colliders attached to the hands and feet of my animation the best approach or should I look at a raycast instead and then just measure the distance between the two gameobjects to determine a hit?

What are the advantages disadvantages to each approach?

Is there another way that I'm not considering?

Comment
Add comment · Show 1
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 Proclyon · Dec 07, 2010 at 07:50 AM 0
Share

Well this is certainly an interesting question! I think I can just give you some advice more than I can an answer. If you are going to work with exact collisions of who hits where when for parts of the rigidbody. You will need know this: http://unity3d.com/support/documentation/Components/class-Rigidbody.html, maybe you can work something out with parenting and joints ins$$anonymous$$d of superprecise high performance cost calculations

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Berenger · Dec 07, 2010 at 08:45 AM

I can explain the method I'm using, but I'm not sure it's a good one (works for me so far).

I get the vector between the player and the target, then the dot product with the vector player_center, player_hand). Finally, I cast a ray along the first vector (player, target) with the dot result as distance max. It might be more clear with a picture : http://yfrog.com/2psanstitreuhkj

Advantages : The damages are applied when the bone is close enough of the enemy, so it match visually. And the animation doesn't need to know about the size of the target.

Disadvantages : The animation have to be created properly, or it wont reach the enemy.

[ EDIT ]

If you are still interested, I just figured an approach wayyyyyyyyy simpler and more efficient. You just need to know at what % of your attack animation occures the hit, like 50%. Then you calcule the animation progression, and if it's higher than 50%, it's a hit (once). Take a look at the code above.

var div : int = animation["attack"].normalizedTime + 0;
var progression = (animation["attack"].wrapMode == WrapMode.Loop) ? animation[anim].normalizedTime - div : animation["attack"].normalizedTime;
if( progression < 0.3 ) didHit = false; // Make sure we hit just once
if( progression > 0.5 && !didHit ) Hit();
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 Pat · Dec 07, 2010 at 03:59 PM 0
Share

How do you set up your character to easily measure the player_center -> player_hand vector?

avatar image Berenger · Dec 07, 2010 at 09:02 PM 0
Share

I need a handle for the hand bone in my script. Two methods here, either with a public var and a drag&drop in the editor, or a script attached to the bone that answer to a "Broadcast$$anonymous$$essage( WhereAreYouHandBone )" with a "Send$$anonymous$$essageUpwards( ThereIAm, this )", something like that. I'm starting to figure out a problem with that approach though, it's possible i'll need to do something different for long range attack (not sure how that's called in english, attack with a bow etc).

avatar image
0

Answer by game_dev23 · May 09, 2019 at 01:03 PM

I'm using a very easy and visualisable system. You can create an empty transform in front of the player and make it a trigger. You can change its height and width to suit your range. Then reference the box using a public variable from your script. Finally use OnTriggerEnter to check if the enemy is in range. Then you can check if the hit input key is pressed and apply the necessary changes to the enemy.

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

1 Person is following this question.

avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Safe area from enemies 1 Answer

OnTriggerEnter - destroy (this.gameobject) if it collides with anything 2 Answers

Looking for help with differentiating collisions between game objects. 2 Answers

How do I get a Not collision? 5 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