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 Clydeicus · Jul 30, 2011 at 04:11 AM · instantiatecolliderruntimeparticleworld

Instantiated object won't collide with particles

I'm working on a flamethrower for a boss, and everything was going well until I tried to make the flamethrower destroy torpedoes launched by the player's ship on contact.

I've already successfully made the flamethrower do damage to the player's ship, and even to other enemy ships. I have also made the flamethrower destroy torpedoes that I manually placed in the editor.

The trouble seems to only affect torpedoes that have been instantiated at runtime.

Is the World Particle Collider unable to detect objects that have been instantiated at runtime?

Here's the script that should be receiving the collision:

     using UnityEngine;
     using System.Collections;
 
     public class Destructible : MonoBehaviour {
 
     public float health = 100f;
     public GameObject explosionPrefab;
     
     private bool destroyed = false;
     
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     if(health <= 0 && !destroyed)
     {
         destroyed = true;
         
         Collider[] nearbyThings = Physics.OverlapSphere(transform.position,200);
         foreach(Collider thing in nearbyThings)
         {
             thing.gameObject.BroadcastMessage("OnNearbyDestruction",gameObject,SendMessageOptions.DontRequireReceiver);
         }
         
         if(explosionPrefab)
         {
             Instantiate(explosionPrefab,transform.position,Quaternion.identity);
         }
         
         
         Destroy(transform.root);
         
         
     }
     
     }
     
     void OnParticleCollision(GameObject other)
     {
         if(other.tag == "Fire") health -= Time.deltaTime * 50;
     }
 }
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
Best Answer

Answer by aldonaletto · Jul 30, 2011 at 04:37 AM

How are you manually placing the torpedoes? Duplicating scene torpedoes? It looks like your torpedo prefab is different from the ones you place manually - Unity doesn't (or shouldn't) make difference between instantiated objects and duplicated ones.

EDITED: I guess you should remove Time.deltaTime from the OnParticleCollision - this will make the damage proportional to how many particles hit the torpedo.
You must use Time.deltaTime in continuous events to have an fps-independent effect - but as far as I know this event occurs only once for each particle hit, what in conjunction with Time.deltaTime would produce an inverse fps dependency: the slower the frame rate, the greater the damage.

    void OnParticleCollision(GameObject other)
    {
        if(other.tag == "Fire") health -= 20; // tweak the damage value as needed
    }
Comment
Add comment · Show 5 · 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 Clydeicus · Jul 30, 2011 at 04:41 AM 0
Share

I'm placing the very same prefab I'm instantiating from. I'll experiment some more and see if I can figure out what's going on.

So far, I've found that placing the prefab in the editor before running the game will create a torpedo affected by the flame thrower. However, a torpedo launched by the player is not affected by the flame- and I've also noticed that a torpedo placed in the editor while the game is running is also unaffected by the fire.

avatar image aldonaletto · Jul 30, 2011 at 05:42 AM 0
Share

I tested instantiated projectiles with a particle collider and it worked fine. Can you post the script which contains OnParticleCollision?

avatar image Clydeicus · Jul 30, 2011 at 05:49 AM 0
Share

Added it to the post-

avatar image Clydeicus · Jul 30, 2011 at 10:24 AM 0
Share

It looks like the collision volume of the particles are quite small, is the problem. The torpedoes appeared to be running into the particles but they only "hit" the particle when it's dead center.

avatar image aldonaletto · Jul 30, 2011 at 10:59 AM 0
Share

I've edited my answer - take a look

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to control World Particle Collider through script 1 Answer

Respawn Player Using a Coroutine 0 Answers

Change value of a projectile that is instantiated in Awake and pooled 1 Answer

Instantiate Prefab Problem 1 Answer

Dynamically parenting a collider object to a rigidbody object causes collision bug. 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