Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 tyler_long_sim · Oct 26, 2013 at 03:19 PM · particlesdestroydistanceemitteroutside

Destroy Particles if they are outside their emitter

Hi, I want to destroy the particles which, when the emitter moves around particles float off into the distance.

This is what ive got so far but it dont work correctly (c#)

     void OnTriggerExit(Collider col)
     { 
         UnityEngine.Object.Destroy(col.collider);
     }
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 Owen-Reynolds · Oct 26, 2013 at 04:19 PM 0
Share

For game speed, I don't think particles interact with the physics engine like regular gameObjects (like OnTrigger*.)

There's a special OnParticleCollision, but it just says "one of your guys hit me", and sounds like it won't fire on triggers.

get/setParticles allows you to see them all. In theory you could hand-check distance in there, if you can find an example.

$$anonymous$$ight be easier just to redo the system (making more particles that live less, so they can't get too far away, inherit more velocity, use local space ... .)

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by justinspice · Jul 22, 2021 at 04:01 AM

you could also just use the trigger event in the particle system and have them killed if they leave a volume

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
avatar image
0

Answer by ShawnFeatherly · Sep 17, 2015 at 02:11 AM

I did something similar by destroying particles that are a certain distance from the emitter:

 using System.Linq;
 /// <summary>
 /// Destroys particles that are farther than DistanceToDestroy from the particlesystem emitter
 /// </summary>
 [RequireComponent(typeof(ParticleSystem))]
 public class ParticleMaxDistance : MonoBehaviour
 {
     public float DistanceToDestroy;

     private ParticleSystem cachedSystem;
     private Vector3 staticPosition;

     void Start()
     {
         cachedSystem = this.GetComponent<ParticleSystem>();
         staticPosition = this.transform.position;
     }

     void Update()
     {
         ParticleSystem.Particle[] ps = new ParticleSystem.Particle[cachedSystem.particleCount];
         cachedSystem.GetParticles(ps);

         // keep only particles that are within DistanceToDestroy
         var distanceParticles = ps.Where(p => Vector3.Distance(staticPosition, p.position) < DistanceToDestroy).ToArray();
         cachedSystem.SetParticles(distanceParticles, distanceParticles.Length);
     }
 }
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

18 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

Related Questions

destroy particle emitter without particles 2 Answers

Particles with collisions still passing through 0 Answers

All instances of particle emitter prefab are emitting when emit=true 0 Answers

How to destroy spawned particle?,How to delete all particle spawned? 0 Answers

Making a hologram effect with particle emitter 2 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