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 PikaSaiyan · Mar 02, 2013 at 04:29 AM · damagerangemelee attack

Area of effect melee attack for 3rd person game?

Hello everyone, I was just wondering if it was possible to create some sort of 'splash' damage (ie: damage in a range around the weapon) and if so, what would be the appropriate way to tackle it. I've looked around online, but almost every tutorial for melee attacking is based off single target attacks. So far the incomplete solutions I've come up with are:

  1. Creating multiple raycasts (somewhat inefficient)

  2. Creating collider meshes that will damage all enemies in its range (Not sure how I should go about with this, but might prove useful since I plan to create a very interactive hitting style like dragging out attack patterns by mouse.)

  3. Damaging everyone within range? (Do I need to do some sort of for loop to apply damage to every enemy in range?)

Let's say I click the mouse to make the character swing a sword: I would want it to hit all enemies in the slice path, rather than locking on and only doing damage to the closest enemy.

I'm really new to Unity, so I'm just looking for any suggestions or examples. Thanks!

Comment
Add comment · Show 3
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 s0lt4r · Jul 17, 2015 at 05:25 PM 0
Share

I'm also trying to figure this out. I've been trying to conceptualize the multiple raycasts but that runs into the issue of stopping when colliding with an object. This, in my case, is undesirable. I did see a function called SphereCast that may be what you're looking for. I'm looking for specific angles not an entire sphere.

avatar image maccabbe · Jul 17, 2015 at 06:12 PM 0
Share

Ins$$anonymous$$d of Physics.Raycast use Physics.RaycastAll. Same thing with Physics.SphereCast, Physics.CapsuleCast, and Rigidbody.SweepTest.

http://docs.unity3d.com/ScriptReference/Physics.html

http://docs.unity3d.com/ScriptReference/Rigidbody.html

avatar image TheLagbringer · Jul 17, 2015 at 06:51 PM 0
Share

I don't feel like answering this since I don't have this specific kind of experience, but two ideas come to my $$anonymous$$d that might be helpful:

  • add collider component to the sword and make your player swing in a large area. This way you simply apply single-target damage to everyone that got hit by the swing.

  • spawn a large projectile (maybe some kind of circle-cut) that travels forward and grows (or simply spawn a growing sphere centered at player's position). It will damage everyone that touches its collider and will disappear after a short amount of time.

I would be careful with overly complicated or multiple raycasts, it may affect the game's performance.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by TechSupportIncoming1 · Jul 17, 2015 at 07:08 PM

Here's a smart way to do it: when splash damage is on(assuming you have a flag for that) and using hit info, create a GameObject (assume it's called GO_SplashDMG, and could be empty) from a prefab at the point of hit.

This GO_SplashDMG prefab has a script attached to it that creates a collider (trigger) in the Start() method of the prefab script.

You then use the message OnTriggerStay() in the prefab script to do something like:

 void OnTriggerStay(Collider other) {
      if(obj.CompareTag("Enemy")){ // other.gameObject.tag == "Enemy"   allocates memory :) Thanks @Vexe :D
           DrainEnemyHP(hitPower);
           StunEnemy(stunPower);
      }
 }

EDIT: OnTriggerStay may cause undesirable effects (in this example: continuous draining of HP and continuous stunning every physical frame as long as the generated prefab clone is not destroyed). So try using OnTriggerEnter if that didn't work out for you.

Do not forget to destroy the prefab automatically and almost instantly when using OnTriggerStay (or whenever you want if you're using OnTriggerEnter; i.e. the timer's duration you set for destroying the prefab clone is the time splash damage lasts for). Also have a rigidbody on each 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

12 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

Related Questions

How Can One Collider Recognize Contact With Another? 0 Answers

Enemy Health Damage 2 Answers

Editing a variable from another script on collision 3 Answers

How to make a falling object cause damage? 1 Answer

Damage trigger? 1 Answer


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