Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Glitshy · Dec 07, 2018 at 08:34 PM · raycastmultiplayerexplosionline of sight

Best way to calculate damage of explosions

I've been wondering which way is the best to accurately calculate the damage an explosion supposed to deal while still being manageable to handle for a multiplayer game. By "accurately" I mean Line of Sight check as well as damage based on how much area of the player's colliders is exposed to the explosion. I've tried the following things so far:

  1. Overlapsphere dealing damage to every "Player" component on a collider inside the radius. This was just a simple test to get to grips with the problem, as it obviously doesn't fulfill my criteria of being "accurate"

  2. Find all colliders within Overlapshpere, shoot a raycast to each collider to check line of sight. As my player model is fairly complex (a human consisting of ~20 colliders) some colliders are hidden by others, meaning raycasts may hit the same collider twice. I simply changed it so that if a hit collider has the same root transform as the actual target collider (i.e. the same player) it still counts as a hit. The main problem however is that especially for larger colliders, a single raycast to the collider's gameobject's position is very accurate. For example, the chest is a single box collider, if the players chest is hidden by more than 50%, so the center of the collider is hidden, the raycast won't hit, despite a decent amount of the chest's area being exposed to the explosion.

  3. Basically, a lot of raycasts. At first, all possibly hit players are stored in a dictionary by checking for colliders with a overlapshere and adding the Player ID (the name of the player gameobject which is individual) string as label to said dictionary, with a float as value (default 0). I have settled on 200 raycasts being drawn spherically using a for-loop with vectors from a pre-calculated vector array. Similar to the shrapnel of an actual explosion. For each raycast hit, the corresponding collider's root transform's name is being compared to the dictionary and then the float value is being increased by the damage of a single hit, let's say +5. If the explosion is going off in front of a player, a lot of raycasts will hit the player's colliders and the value in the dictionary will rise. After the for-loop I deal the corresponding damage to each player in the dictionary. If a player was further away or partially in cover relative to the explosion, he will have been hit by fewer raycasts and therefore less damage will be dealt.

System 3 works as far as I can tell the way I want it to, however I feel like it might by quite resource demanding to draw this many raycasts and I wonder if there may be a more elegant system to achieve my desired goals.

Thanks for reading and any help appreciated.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Jadlar · Aug 03, 2019 at 07:40 PM

Hi, i'm not sure what kind of game you are making at the moment but I have something similar with some tweaks. I'm making a 3D FPS at the moment and I use both raycast and overlap-sphere.

For mine instead of using 200 raycast i use about 10. First I use the overlap sphere to determine if the collider of an object is within the damage zone. Then, if an object is within an explosion radius then i draw 10 raycast: 1 on the head, 1 on the ground near feet, 4 in a even shape around the shoulders, and 4 near the knees in an even shape. Doing it like this allows you to check if the player is behind walls as well. If a point is hit then I calculate damage by (amount of points hit x base damage x distance from the center of collision). Use raycast hit.distance to find the distance from the hit point to the center of the explosion. Using this calculation works well for me. through play testing I set different distance variables to correspond with a damage multiplayer. For example in a 10 radius bomb if the a point of the player is hit within a 2.5 radius zone from the center I multiply ( one point hit x 0.20 x distance-check) distance-check in my case determines that the variable equals 1000 if a point is within a 2.5 radius space. Thus the damage taken is 200 guaranteeing me a instant kill (100 points of health 100 points of armor) from a grenade or rocket. Or if a single point is hit at radius 9 the variable = 90 (1 x 0.20 x 90) dealing 18 points of damage. Variables can be tweaked as needed.

The points to check for can also be attached to the skeleton of a model if that is something you are using. Hope this helps!

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

259 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image

Related Questions

Raycast shooting impact effect position problem 1 Answer

AddExplosionForce not affecting every rigidbody 1 Answer

Spawning objects uNet Client and Local 0 Answers

Raycast over Photon 0 Answers

checking line of sight with raycasts (2D) 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