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 Olgo · May 20, 2016 at 02:32 PM · 2dspritepositionparticle systemparticle

Setting particle position every frame...

I'm trying to get my particles to layer nicely with my sprites as displayed here:

https://twitter.com/moaiHeadOlgo/status/732378209782779904

My problem is, I need to set the particles' z position every frame. When I do this, the particle looks like its z-fighting the sprite its supposed to be behind.

The reason for this, is so the torch flame can appear infront of / behind the player depending on what direction the player is facing.

I've tried doing "particleSys.Emit()" and passing in position parameters but then I lose all the nice functionality of the particle system prefabs.

Help! Thanks!

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 FortisVenaliter · May 20, 2016 at 02:43 PM

Do the particles have any movement predefined that might cause them to move a bit each frame from where you place them?

If not, are you placing them on the exact same z as the character? Or slightly ahead/behind?

Seeing your code would definitely help if neither of the previous two suggestions help.

Comment
Add comment · Show 11 · 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 Olgo · May 20, 2016 at 02:51 PM 0
Share

Thanks for your reply!

There is no movement predefined other than Velocity over TIme = (0,1,0) in World space. No other script manipulates the position of the particles.

The particle system is a prefab that is placed on the torch slightly in front. I take the torch's position and add -.001 to the z value of the particle. Here's my code:

 ParticleSystem.Particle[] particles;
 ParticleSystem partSys;
 
 void Update(){
 
   int numAlive = partSys.GetParticles(particles);
 
   for( int i = 0; i < particles.length; i++){
     particles[i].position = new Vector3( particles[i].position.x, particles[i].position.y, transform.parent.position.z - .001f);
   }
 
   partSys.SetParticles(particles, numAlive);
 
 }
avatar image FortisVenaliter Olgo · May 20, 2016 at 02:55 PM 0
Share

Have you tried upping that offset? Try -0.1f or -1f and see what happens.

avatar image Olgo FortisVenaliter · May 20, 2016 at 03:07 PM 0
Share

Yes, but the value needs to be small to fit between the torch at .001 and the head at -.001. Therefor, the value needs to be smaller than .002 to still be rendered behind the head.

I ran a test, I put the same code in a coroutine that runs once every second. The particles go to their proper position every second, but the very next frame they are back on top. I think this is a matter of the particles needing to be set every frame BEFORE they are drawn by the particle system.

Show more comments

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

80 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

Related Questions

How do I check if/where in a sprite another sprite is? 0 Answers

how can I get particle.position out of shuriken system? 2 Answers

Particle system, unaffected by attached sprite 1 Answer

Why animation events do not change sprite position? 1 Answer

Change Sprite Origin in 2D 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