• 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 TSI25 · Oct 21, 2014 at 11:52 PM · particlesystem2d rotation

rotate particle effect emission based on motion vector

alright so i have a gameobject thats moving around on the screen, it is not being controlled by a player, its just bouncing around. this movement is based on 2d rigidbody physics.

one of the children of this gameobject is a particle system thats spitting out an effect. i need to rotate the emission of the effect so it looks as though its trailing behind the parent object (direction matters).

how can i rotate the particle system to face the motion vector of the parent. ideally i want to do this without rotating the parent. if anyone can even point me to a function that might be useful for that, it would be great. if i can just get a nudge in the right direction i can probably write the code myself.

Comment
Add comment · Show 3
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 robertbu · Oct 22, 2014 at 12:16 AM 0
Share

First a particle effect and a particle system are two different things, so your title might be misleading to some. Second I don't understand your question. Assu$$anonymous$$g you left your simulation space as local, you should be able to just aim the forward of the child in any direction you want with respect to the parent, and the particles will shoot that direction. If the parent's forward does not match the motion, then you can do this in the child with the particle system:

   transform.rotation = transform.LookRotation(directionOf$$anonymous$$otion);

I don't know how you are moving your parent. If you are using a Rigidbody, you can use 'transform.parent.rigidbody.velocity for the directionOf$$anonymous$$otion.

avatar image TSI25 · Oct 22, 2014 at 01:23 PM 0
Share

well then for clarity's sake I'm working with a particle system. I've tried accessing the parents 2d rigidbody velocity but it gives me a static amount that doesnt actually seem to represent a motion vector. Heres the script I'm now working with.

         public class ParticleRendererRotater : $$anonymous$$onoBehaviour {
     
             public ParticleSystem particleSystem;
     
             private Rigidbody2D rigidBody2D;
     
             private void Update()
             {
     
                 Vector3 directionOf$$anonymous$$otion = new Vector3 (rigidBody2D.velocity.x, rigidBody2D.velocity.x, 0);
                 Quaternion rotation = Quaternion.LookRotation(directionOf$$anonymous$$otion);
                 transform.localRotation = rotation;
                 //particleSystem.startRotation = rotation.z;
             }
     
             private void Start()
             {
                 rigidBody2D = transform.parent.rigidbody2D;
             }
         }


At any rate this doesnt seem to have any effect on the direction the particles are emitted from, even if they or their parent rotates they themselves dont. (I Can't use local particle rendering because if the object bounces off a wall i need the particle trail left behind to reflect that). I wasn't able to find anything resembling a 'transform.LookRotation', i assume you meant 'Quaternion.LookRotation'?

I think im going to need to access the particleSystem.StartRotation which takes a float and not a quaternion. I'll start looking into any kind of quaternion -> float function but if anyone knows what that looks like in the mean time, please let me know.

avatar image robertbu · Oct 22, 2014 at 10:05 PM 0
Share

This line is suspect:

   Vector3 directionOf$$anonymous$$otion = new Vector3 (rigidBody2D.velocity.x, rigidBody2D.velocity.x, 0);

Why are you using 'velocity.x' for both the 'x' and the 'y' component of the Vector3 you are building.

And this:

   transform.localRotation = rotation;

...will only work if your parent's rotation is (0,0,0) in which case there is no reason to use localRotation rahter than rotation.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

27 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

Related Questions

ParticleSystem can‘t Simulate in the Editor mode 1 Answer

slow mobile lightbeam 0 Answers

Change Size over Lifetime for Particle System? 1 Answer

Stop smoke fading when character walks into it? 0 Answers

How unity evaluate Random Between two curves type property in ParticleSystem? 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