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 /
avatar image
0
Question by lonelycamper · Mar 20, 2018 at 06:40 PM · unity 5colliderhitbox

How to add hitboxes firstperson shooting

Im wondering how I can go about differentiating different body parts of the player using colliders how would I go about checking individual colliders thru code (ex if a player gets shot in the head vs the body) how can I chech which collider is getting hit and change the damage value getting sent to the player health Sorry if this sounds confusing im having trouble wording it right now

Comment
Add comment · Show 2
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 lonelycamper · Mar 20, 2018 at 07:42 PM 0
Share

And if I got this working would sphere colliders or box colliders be a better choice

avatar image hexagonius · Mar 20, 2018 at 07:56 PM 0
Share

what suits the shape of your bodies better. Just make each body part a transform (in case of a rig that's already the case) and add one collider each. when you detect these by raycast you could use the names. if you do this by real collision you'd need to check each point of the collision objects contacts and see what otherCollider was.
if these colliders do not handle anything besides hit detection, they could just be made triggers, for raycasting and triggering with other colliders.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Rexro · Mar 21, 2018 at 02:17 AM

Are all the body parts separate child objects of the player? If so I would create a script to add to all the body parts in which would have a OnCollisionEnter() method. In this method I would call a method from a script attached to the player which would take in a parameter determining which body part just called it (I will use an enum) and use if statements to deal different damages. Here is the script attached to all the body parts:

 public class ChildCollision : MonoBehaviour {
     GameObject parent;
     public BodyTypes thisPart;
     void Start () {
         parent = transform.parent.gameObject;
     }
     private void OnCollisionEnter(Collision collision)
     {
         parent.GetComponent<ParentCollision>().OnChildCollisionEnter(thisPart);
     }
 }

And Here is the script Attached to the player:

 public enum BodyTypes
 {
     Head, Body, Arms, Legs
 }
 public class ParentCollision : MonoBehaviour {
     
 
     public void OnChildCollisionEnter(BodyTypes part)
     {
         if(part == BodyTypes.Head)
         {
             //If collision hit the head
         }
         if (part == BodyTypes.Body)
         {
             //If collision hit the body
         }
         if (part == BodyTypes.Legs)
         {
             //If collision hit the legs
         }
         if (part == BodyTypes.Arms)
         {
             //If collision hit the arms
         }
     }
 }






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

164 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

Related Questions

Rigidbody goes crazy when isKinematic is false 1 Answer

Ball passing through triggered collider 0 Answers

Moving a object randomly without it being inside a wall 1 Answer

How to decrease the speed of the player by some fraction after triggering the box collider? 2 Answers

Sprites not recognized as whole-spinning in different directions 0 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