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
0
Question by Abidus · Mar 17, 2014 at 05:06 PM · collisionontriggerenterdamagerocketmessages

Rocket projectile damage not applied on collision (message not sent/received)

I am trying to get a rocket launcher to apply damage on collision between the rocket and an object tagged with "Enemy".

The objects are colliding, but the enemy object is not taking any damage (message is not being sent?), and my debug logs (collision detected, damage received) are not showing up either.

Both the rocket and enemy objects have a rigid body and a capsule collider.

Here's my "RocketDamage" script, attached to the Rocket prefab:

 #pragma strict
 
 var damage = 25;
  
 
   function OnTriggerEnter(collider:Collider)
   {
       if (collider.CompareTag("Enemy")) 
       {
           collider.gameObject.SendMessage("ApplyDamage", damage);
           Debug.Log("Collision detected!");
       }
   }

and my DamageController script (attached to enemy object):

 #pragma strict
 
 @script RequireComponent(Rigidbody)
 
 var hitPoints = 100;
 var explosionDelay = 0.0;
 var explosion : Transform;
 
 function ApplyDamage(damage : float) {
 
     if (hitPoints <= 0.0) 
     {
     return;
     }
 
     hitPoints -= damage;
     Debug.Log(hitPoints + " - HP remaining.");
 
     if (hitPoints <= 0.0)
     {
         var emitter : ParticleEmitter = GetComponentInChildren(ParticleEmitter);
         if (emitter)
         emitter.emit = true;
         
         Invoke("DelayedExplosion", explosionDelay);
     }
 
 
 
 }
 
 function DelayedExplosion() {
     BroadcastMessage("Detonate");
     }
 
 function Detonate() {
     Destroy (gameObject);
 
     if (explosion) {
     Instantiate (explosion, transform.position, transform.rotation);
     }
 
     var emitter : ParticleEmitter = GetComponentInChildren(ParticleEmitter);
         if (emitter) {
         emitter.emit = false;
         particleEmitter.transform.parent = null;
         }
 }
 

Would appreciate any ideas on why this is happening. Thanks for your time!

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 AlucardJay · Mar 17, 2014 at 06:55 PM 0
Share

Is the object tagged as Enemy? Check what tag you are hitting by adding this before the conditional (if statement) :

 Debug.Log("Collision detected! tag = " + collider.gameObject.tag);
avatar image Olgo · Mar 17, 2014 at 06:58 PM 0
Share

another one of the basics, do you have a collider with "isTrigger" box ticked on the RocketPrefab

avatar image Abidus · Mar 18, 2014 at 01:23 AM 0
Share

@alucardj The object is properly tagged as enemy. Thanks for the input nonetheless.

@Olgo: I actually managed to get the functionality to work with OnCollisionEnter ins$$anonymous$$d of OnTriggerEnter. I am thinking this is why the latter wasn't working properly (silly me). Thanks!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Abidus · Mar 18, 2014 at 02:25 AM

I actually managed to get the functionality to work with OnCollisionEnter instead of OnTriggerEnter. I think the collider on the rocket was not set to be a Trigger, which is why OnTriggerEnter was not functioning properly.

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

22 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

Related Questions

On Trigger Enter, Collide with object, specific collision 1 Answer

Trigger Spawning? 1 Answer

My rockets don't do damage? 1 Answer

Colliding two GameObjects 1 Answer

Area of Damage for a Blink of an Eye 3 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