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 /
This question was closed Jul 31, 2018 at 07:46 AM by BluesyPompanno for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by BluesyPompanno · Jul 30, 2018 at 06:02 PM · triggercollidersdamagecollisionsmelee

Gameobject not registering collisions

Hello.

I am have a small problem. I have currently switched to Unity 2018.2.1f.


In my game the player can attack using various weapons. The way my player deals damage is by a cube that is placed infront of the player ( Damager ) with box collider set to triger.My enemy has capsule collider set to triger.


My problem is when the enemy collides with the Damager gameobject no damage gets applied.


Here is my script for the Damager gameobject.

  Hrac_WEAPONMANAGER hrcWeaponManager;
 
     public float damageToDeal;
     BoxCollider damageCollider;
 
     public Material colliderOFF;
     public Material colliderON;
 
     Material currentMaterial;
 
 
     private void Start()
     {
         damageCollider = GetComponent<BoxCollider>();
         damageCollider.enabled = false;
 
         currentMaterial = GetComponent<Renderer>().material;
         currentMaterial.color = colliderOFF.color;
     }
 
     // Update is called once per frame
     void Update ()
     {
         if(GetComponentInParent<Hrac_WEAPONMANAGER>() != null)
         {
             hrcWeaponManager = GetComponentInParent<Hrac_WEAPONMANAGER>();
             damageToDeal = hrcWeaponManager.damage;
         }     
     }
 
     public void colliderActivator()
     {
         StartCoroutine(colliderActive());
     }
 
     IEnumerator colliderActive()
     {
         damageCollider.enabled = true;
         currentMaterial.color = colliderON.color;
 
         yield return new WaitForSeconds(0.5f);
 
         currentMaterial.color = colliderOFF.color;
         damageCollider.enabled = false;
     }
 }
 

and here is the script for enemy health

     public float maxHealth;
     public float currentHealth;
 
 
    void Start ()
     {
         currentHealth = maxHealth;
     }
    
 
  
 
     void OnTriggerEnter(Collider other)
     {
         if (other.gameObject.tag == "DAMAGER")
         {
             Hrac_DAMAGER hrcDamager = other.GetComponent<Hrac_DAMAGER>();
             currentHealth = currentHealth - hrcDamager.damageToDeal;
         }
     }
 
     void Update()
     {
         if (currentHealth <= 0f)
         {
             Destroy(gameObject);
         }
     }
 
 }

This code is taken from my older project and everything works perfectly with no problems on older versions of Unity. Does anybody knows what might be the problem ?

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 cryingwolf85 · Jul 31, 2018 at 12:51 AM 0
Share

First issue: maybe the code is missing, but I'm not seeing anything that's calling 'colliderActivator()'.

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by Carterryan1990 · Jul 31, 2018 at 01:00 AM

Does your object have a rigidbody? If not add one and Set Iskinematic to true. For collisions and triggers to take place and register one of the objects needs to have a rigidbody.

Comment
Add comment · Show 1 · 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 BluesyPompanno · Jul 31, 2018 at 07:46 AM 0
Share

I am an Idi*t. $$anonymous$$y object didn't had rigidbody.No wonder it didn't work. :D

Thank you !

Follow this Question

Answers Answers and Comments

107 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

Related Questions

How to use multiple Colliders for an enemy to detect multiple collisions in different areas to determine the damage to the enemy? I.E. Headshot etc. 1 Answer

Trigger and ennemy damage 2 Answers

Child Object's collider setting off triggers 1 Answer

Inconsistent Trigger events 1 Answer

Temporary invulnerability in a platformer 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