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 wightwhale · Mar 17, 2016 at 03:13 PM · terrainparticlesparticlesystemshurikenterraindata

How do you get particles to follow along the terrain?

I'm trying to make a particle system which follows the ground built with unity's terrain. Is there a way to tell the particles to follow the terrain or is it something I'm going to need to make myself by getting the current terrain height and updating the particles as they flow?

Comment
Add comment · Show 2
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 wightwhale · Mar 16, 2016 at 07:55 PM 0
Share

Got it working eventually so posting here in case anyone else has the same issue. I have a function which updates particle system position with terrain height and a function to rotate individual particles with the surface normal of the terrain. The 2nd part was much harder than the first.

         private void $$anonymous$$oveParticlesOnTerrain(ParticleSystem ps)
         {
             int numParticlesAlive = ps.GetParticles(m_Particles);
             if (m_Particles == null || m_Particles.Length < ps.maxParticles)
                 m_Particles = new ParticleSystem.Particle[ps.maxParticles];
 
 
             // Change only the particles that are alive
             for (int i = 0; i < numParticlesAlive; i++)
             {
                 RaycastHit raycastHit;
                 Ray r = new Ray(m_Particles[i].position + Vector3.up * 100f, Vector3.up * -1f);
                 if (Physics.Raycast(r, out raycastHit, terrainLayer))
                 {
                     Quaternion rot = Quaternion.FromToRotation(Vector3.forward, raycastHit.normal);
 
                     m_Particles[i].axisOfRotation = Vector3.forward;
                     m_Particles[i].rotation3D = rot.eulerAngles;
 
                     m_Particles[i].position = new Vector3(m_Particles[i].position.x,
                         gravity.currentTerrain.SampleHeight(m_Particles[i].position) + .1f,
                         m_Particles[i].position.z);
                 }
             }
 
             ps.SetParticles(m_Particles, numParticlesAlive);
         }
 
         private void $$anonymous$$oveParticleSystemOnTerrain(ParticleSystem ps)
         {
             ps.transform.position = new Vector3(ps.transform.position.x,
                 gravity.currentTerrain.SampleHeight(ps.transform.position) + .1f,
             ps.transform.position.z);
         }
     
avatar image arturmandas · Jan 02, 2017 at 08:07 PM 0
Share

Hi, thank you! I was looking for a solution to create sand particles, and stumbled upon your post. You use raycasting here - how about performance with, let's say, 10000 particles? Also, why is there "gravity.currentTerrain.SampleHeight" -> you sample heighmap, offset by 0.1, but why "gravity" ? Thank you?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ash_richie · Mar 17, 2016 at 07:12 PM

just create particles and keep it under your player as child

and itll follow u

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 wightwhale · Mar 17, 2016 at 08:38 PM 0
Share

Well that works if you want the particles just on the player and not out on the terrain somewhere.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Change particles per burst from code 2 Answers

Are there any disadvantages to using the legacy Ellipsoid Particle System in Unity 5 over Shuriken. 0 Answers

Make particle system cover terrain? 1 Answer

Shuriken Particles - is there away to reverse a particles speed over its lifetime when emitting from a circle or sphere? 1 Answer

Runtime terrain painting with SetAlphamaps = lag 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