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 /
  • Help Room /
avatar image
0
Question by subver · Nov 07, 2019 at 09:47 PM · particlesparticlesystem

Trying to repel/scatter particles in the vicinity of a GameObject, have particles return to position after

Hey there, I'm having some trouble figuring out how particles work with what I have in mind.

Right now I have a particle system that places a particle for each pixel of an image texture. I want a simple sphere (assume attached to the mouse cursor) that repels/scatters the particles, like a magnet, and have the particles move back into place. They would ideally have velocity tied to how fast they were collided with so it's not just static. I'm picturing, basically something like this: (best I could find) alt text

This is the script I'm using for the text to particle... I'm having trouble going from here, though. Any help would be great! I've been playing with attractors and it isn't working how I want... to have the particles come back after being scattered/dispersed.

 public Texture2D texture;
     public float scale = 1;
     public float particleSize = 1;
     public ParticleSystem system;
 
     public int numberParticlesX = 64;
     public int numberParticlesY = 64;
     
     void Update ()
     {
         ParticleSystem.Particle[] particles = new ParticleSystem.Particle[numberParticlesX * numberParticlesY];
         system.maxParticles = particles.Length;
         system.Emit(particles.Length); // Creates the particles.
         system.GetParticles(particles);    // Get them so we can adjust the values
         Vector2 pixelOffset = new Vector2(texture.width / numberParticlesX, texture.height / numberParticlesY);
         
         int index = 0;
         Vector3 pos = Vector3.zero;
         for(int y = 0; y < numberParticlesY; ++y)
         {
             for (int x = 0; x < numberParticlesX; ++x)
             {
                 // Sample the pixel value(we could so some interpolation here).                
                 particles[index].position = pos;
                 particles[index].color = texture.GetPixel(Mathf.RoundToInt(pixelOffset.x * x), Mathf.RoundToInt(pixelOffset.y * y));
                 particles[index].size = particleSize;
                 index++;
                 pos.x += pixelOffset.x * scale;
             }
             pos.y += pixelOffset.y * scale;
             pos.x = 0;
         }
 
         system.SetParticles(particles, particles.Length);        
     }


Anyway thanks so much for taking the time to read this. I appreciate any help or suggestions!

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

0 Replies

· Add your reply
  • Sort: 

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

192 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 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

Circle shape emitter is flipping particles on one side 1 Answer

Ignore collision for a single billboard particle? 0 Answers

RayCast on particle system 0 Answers

How to Instantiate decals where particles from particle system hits? 1 Answer

Particles with collisions slip/glitch through corners of edge Collider 0 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