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
1
Question by FuryFight3r · Oct 11, 2017 at 07:04 PM · colliderschild objectdetecting

Collider collision not being detected on fast passed objects

I have designed a health system for a zombie game i am intending to make, and want to have certain damage for certain body parts hit, for example, limb shot 25hp, body shot 45hp, head shot instant kill.... but i'm not sure at all where i am going wrong, i know what really screws me over is having to instantiate each object so i can't simply drag and drop the head to head and body to body in the hierarchy, I have to find each one individually through code and then use that Object to source a collider that is attached that object

So i have a bullet object with the tag of 'Bullet', it has a rigidbody and box collider.

I also have a Rigged Zombie tagged 'Zombie' which has an animator, Navigation script, navmesh agent, the zHealth script, a rigidbody and colliders marked as triggers on each shootable rig bone (Head, L Arm, R Arm, Body, R Leg, L Leg).

So what i would want to happen is i shoot the gun, the bullet is instantiated, bullet travels, hits target collider, deals damage then removes the bullet.

What actually happens, i shoot the gun, the bullet is instantiated, bullet travels, passes through target collider, bullet lands never to be found again, no damage dealt, no hit detected.

Coding Notes: Yes i understand that having bullets and bullet casings laying around that do not get removed if a collision is not met can be very demanding, but this is a part of the esthetic of the game, i will find a way for this to be less demanding and if all else fails then a system for when a certain number of casings/bullets are laying around the first bullet that was laying on the ground will be removed ect.

Added OnTriggerExit thinking the bullet may be traveling too fast for OnTriggerEnter to detect the collision.

Tried with and without else if () statements within OnTriggerEnter & OnTriggerExit.

Have had only one collision for a headshot and this was just after i figured out i needed a rigidbody on the zombie to detect collisions on child objects but after adding the rest of the body parts to the hit collision list, it some how stopped working.

Also undid all the coding to just after i added the rigid body and still never detected collision again.

I had a very basic healthsystem "working" earlier, but decided to re write it, because about 20% of direct hit collisions would detect, and overall was a lot more harsh on fps.

More notes may come, i just wanted to point out that i am only seeking help for why the bullets are not being detected, not criticism on the path i chose for an unique esthetic style game.

Current Coding:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class zHealth : MonoBehaviour {
 
     public bool dead = false;
 
     public float zHlth;
 
     private Rigidbody rig;
 
     private chase aiScript;
     private hitmarker hm;
     private crosshair ch;
     private GameObject player;
 
     private GameObject zHead, zBody, zlArm, zrArm, zlLeg, zrLeg;
     public Collider zHeadCol, zBodyCol, zlArmCol, zrArmCol, zlLegCol, zrLegCol;
 
 
 
     private void Start()
     {
         aiScript = gameObject.GetComponent<chase>();
         player = GameObject.FindGameObjectWithTag("Player");
         ch = player.GetComponent<crosshair>();
         hm = player.GetComponent<hitmarker>();
         rig = gameObject.GetComponent<Rigidbody>();
 
         zHead = transform.Find("_no_name_/Main__Hips_/LowerBack/Back/Chest/Neck").gameObject;
         zHeadCol = zHead.GetComponent<SphereCollider>();
 
         zBody = transform.Find("_no_name_/Main__Hips_/LowerBack/Back/Chest").gameObject;
         zBodyCol = zBody.GetComponent<BoxCollider>();
 
         zlArm = transform.Find("_no_name_/Main__Hips_/LowerBack/Back/Chest/LeftUpperArm").gameObject;
         zlArmCol = zlArm.GetComponent<CapsuleCollider>();
 
         zrArm = transform.Find("_no_name_/Main__Hips_/LowerBack/Back/Chest/RightUpperArm").gameObject;
         zrArmCol = zrArm.GetComponent<CapsuleCollider>();
 
         zlLeg = transform.Find("_no_name_/Main__Hips_/LeftUpperLeg").gameObject;
         zlLegCol = zlLeg.GetComponent<CapsuleCollider>();
 
         zrLeg = transform.Find("_no_name_/Main__Hips_/RightUpperLeg").gameObject;
         zrLegCol = zrLeg.GetComponent<CapsuleCollider>();
     }
 
     private void OnTriggerEnter(Collider hit)
     {
         if (zHeadCol.CompareTag("Bullet"))
         {
             Destroy(hit.gameObject);
             hm.getHitMarker();
             hit.GetComponent<Rigidbody>().useGravity = false;
             Debug.Log("Bullet has hit zHead");
             headShot();
         }
         else
         if (zBodyCol.CompareTag("Bullet"))
         {
             hm.getHitMarker();
             hit.GetComponent<Rigidbody>().useGravity = false;
             Debug.Log("Bullet has hit zBody");
             bodyShot();
             Destroy(hit.gameObject);
         }
         else
         if (zlArmCol.CompareTag("Bullet"))
         {
             hm.getHitMarker();
             hit.GetComponent<Rigidbody>().useGravity = false;
             Debug.Log("Bullet has hit zLeftArm");
             limbShot();
             Destroy(hit.gameObject);
         }
         else
         if (zrArmCol.CompareTag("Bullet"))
         {
             hm.getHitMarker();
             hit.GetComponent<Rigidbody>().useGravity = false;
             Debug.Log("Bullet has hit zRightArm");
             limbShot();
             Destroy(hit.gameObject);
         }
         else
         if (zlLegCol.CompareTag("Bullet"))
         {
             hm.getHitMarker();
             hit.GetComponent<Rigidbody>().useGravity = false;
             Debug.Log("Bullet has hit zLeftLeg");
             limbShot();
             Destroy(hit.gameObject);
         }
         else
         if (zrLegCol.CompareTag("Bullet"))
         {
             hm.getHitMarker();
             hit.GetComponent<Rigidbody>().useGravity = false;
             Debug.Log("Bullet has hit zRightLeg");
             limbShot();
             Destroy(hit.gameObject);
         }
     }
 
     private void OnTriggerExit(Collider hit)
     {
         if (zHeadCol.CompareTag("Bullet"))
         {
             hm.getHitMarker();
             hit.GetComponent<Rigidbody>().useGravity = false;
             Debug.Log("Bullet has hit zHead, Target Instantly Killed, Bullet Removed");
             headShot();
             Destroy(hit.gameObject);
         }
         else
         if (zBodyCol.CompareTag("Bullet"))
         {
             hm.getHitMarker();
             hit.GetComponent<Rigidbody>().useGravity = false;
             Debug.Log("Bullet has hit zBody");
             bodyShot();
             Destroy(hit.gameObject);
         }
         else
         if (zlArmCol.CompareTag("Bullet"))
         {
             hm.getHitMarker();
             hit.GetComponent<Rigidbody>().useGravity = false;
             Debug.Log("Bullet has hit zLeftArm");
             limbShot();
             Destroy(hit.gameObject);
         }
         else
         if (zrArmCol.CompareTag("Bullet"))
         {
             hm.getHitMarker();
             hit.GetComponent<Rigidbody>().useGravity = false;
             Debug.Log("Bullet has hit zRightArm");
             limbShot();
             Destroy(hit.gameObject);
         }
         else
         if (zlLegCol.CompareTag("Bullet"))
         {
             hm.getHitMarker();
             hit.GetComponent<Rigidbody>().useGravity = false;
             Debug.Log("Bullet has hit zLeftLeg");
             limbShot();
             Destroy(hit.gameObject);
         }
         else
         if (zrLegCol.CompareTag("Bullet"))
         {
             hm.getHitMarker();
             hit.GetComponent<Rigidbody>().useGravity = false;
             Debug.Log("Bullet has hit zRightLeg");
             limbShot();
             Destroy(hit.gameObject);
         }
     }
 
     public void headShot()
     {
         zHlth = 0;
     }
 
     public void bodyShot()
     {
         zHlth -= 45;
     }
 
     public void limbShot()
     {
         zHlth -= 25;
     }
 
     private void FixedUpdate()
     {
         if (zHlth <= 0)
         {
             dead = true;
             rig.isKinematic = true;
             rig.useGravity = false;
             aiScript.isDead();
             hm.died();
             ch.died();
         }
     }
 }
 


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 jchester07 · Oct 12, 2017 at 02:00 AM 0
Share

So you are using OnTrigger that means your bullet's collider is a trigger collider, right? Have you set the collision detection of your rigidbody to continuous/continuous dynamic?

I've checked your code. you're not using the parameters of OnTrigger

 private void OnTriggerEnter(Collider hit)
      {
          if (**zHeadCol**.CompareTag("Bullet"))
          {
              Destroy(hit.gameObject);
              hm.getHit$$anonymous$$arker();
              hit.GetComponent<Rigidbody>().useGravity = false;
              Debug.Log("Bullet has hit zHead");
              headShot();
          }


It should be

 private void OnTriggerEnter(Collider hit)
          {
              if (**hit**.CompareTag("Bullet"))
              {
                  Destroy(hit.gameObject);
                  hm.getHit$$anonymous$$arker();
                  hit.GetComponent<Rigidbody>().useGravity = false;
                  Debug.Log("Bullet has hit zHead");
                  headShot();
              }

and by the code you provided, you have added multiple colliders. but these colliders would be considered as one collider for the parent gameobject.

avatar image FuryFight3r jchester07 · Oct 14, 2017 at 06:03 AM 0
Share

Ah that was my mistake, I had changed the bullet from isTrigger to not (from changing things back and forth to try rectify the issue of not hitting 100% of the time), but have reverted back now, but still the collision is only detected about once every 10 direct hit shots, and yes as you were saying all the colliders clash, I could shoot the leg of the zombie, and I would get a message of "Bullet has hit zHead, Target Instantly $$anonymous$$illed, Bullet Removed", how can I make the collisions happen 100% of the time and how can I make individual impacts for different body parts ie individualise the colliders for arms legs, body and head?

avatar image jchester07 FuryFight3r · Oct 16, 2017 at 06:15 AM 0
Share

I stumbled also on that problem as any collider in your child gameobject would trigger the parent's collision as if it was the parent's collider component. I haven't actually tried it yet but you can make a collision script for each body part and once it is hit and method/functions OnTriggerEnter() is called, then you call the methods/functions from your health script.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Injec · Oct 12, 2017 at 02:11 PM

If the bullet has a Rigidbody, set it's Collision detection to "Continuous Dynamic". And make your questions shorter please, i guess then you get more answeres ;)

Comment
Add comment · Show 3 · 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 FuryFight3r · Oct 14, 2017 at 06:08 AM 0
Share

Sorry this was not the issue, the bullet has always had a Continuous as well as Continuous Dynamic Collision Detection, because of its fast paced movement needing to be tracked continuously.

The reason my hits had stopped working though was because i changed the bullet Prefab to isTrigger = false when it most definitely should have been true, but i will try anything to fix an issue i'm having. but have had no avail hence why im here asking.

and everyone is different, i could put a 2 sentence question and it would be too short, and non descriptive, but then when you write a perfect description of everything that is going wrong and everything that you may think that could help towards a better answer, is going to be too long, just depends on the person answering weather they can be bothered to read long questions or weather they are genuinely in this just for the cookie points

avatar image Vollmondum FuryFight3r · Oct 14, 2017 at 06:19 AM 0
Share

Any trigger or collision detection you can replace with bullet/target coordinates. Say, if collision fails at some point, you run a function to check if the bullet was near. Not that perfect, but still a solution

avatar image gamedevelopmenttsunami · Apr 30, 2019 at 02:35 PM 0
Share

Detection modes are actually not very good at detecting fast moving objects. Use a solution more like this: https://answers.unity.com/questions/1174027/object-moving-too-fast-so-that-the-collider-does-n.html?childToView=1627279#answer-1627279

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

74 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

Related Questions

Child colliders affecting parent rigidbody characteristics? 0 Answers

Connect a collider with a rigidbody ?? 1 Answer

physics.OverlapSphere colliders 1 Answer

How can I disable the collider collision of a ragdolls specific bones? 0 Answers

Collider only works as a child object 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