Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Mernion · Feb 22, 2015 at 04:28 PM · c#particle

Change particle velocity when gameobject rotates

Im trying to create a little game with a space ship and encountered a small problem with trail of space ship engine. I've created a particle and wrote a small script which increase start lifetime and size of particles to produce visual effect of ship speed increasing. But, when my ship rotates I want to show that trail of ship rotates slowly also (currently my trail always looks like straight line and i want to modify it so it will look like curve when my ship rotates). So, I have several variables from my "movement script": speed of ship, vector to target and angel between ship and target. After using google I found a way to change velocity of particle with the help of next code:

 public void UpdateDirection()
 {
   float distance = 5;
   ParticleSystem.Particle[] particles = new    ParticleSystem.Particle[particle.particleCount];
   int count = particle.GetParticles(particles);
   for(int i = 0; i < count; i++)
   {
        float xVel = (particles[i].lifetime / particles[i].startLifetime) * distance;
        particles[i].velocity = new Vector3(xVel, 0, 0.2f);
   }            
     particle.SetParticles(particles, count);
 }

I've tried several diff. ways of modifying velocity with my vector.x coordinate, angel and etc, but after this my particle worked very strange way, like without any lifetime, or just bursting in left or right side. How can I use my data to modify velocity and move from straight line to curve trail? Pls help :(

EDIT: Excuse me to bringing back this question, but after sometime I realised that simulation space isnt helping me with that problem. Currently it rotates right at the emit point and this is bad, because it looks ugly. I need some way of applying force to particle after sometime, like script option of "force over lifetime" (I cant use this direct from unity editor, because rotating is random)

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 karljj1 · Feb 22, 2015 at 11:27 PM 1
Share

To get the trail to curve modify the particles angularVelocity.

It sounds like a lot of what you are doing can be done using the ParticleSystem without code.

For example the Size By Speed and Color By Speed tabs could help replace your current method. Set the simulation space to be world. Set inherit velocity to 1.

avatar image Mernion · Feb 23, 2015 at 10:29 AM 0
Share

I cant mark you comment as answer, so just thx you! :p Need to rework my particle system after that, but they look like curve now.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by hexagonius · Feb 23, 2015 at 07:58 AM

It's definitely simulation space world as karljj1 said. But inherit velocity should be 0. You don't need to script anything for that

Comment
Add comment · Show 5 · 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 Mernion · Feb 24, 2015 at 06:06 PM 0
Share

Err, after some homework I realised that this is not helping me with problem. Can i somehow script "force over lifetime" behavior?

avatar image karljj1 · Feb 24, 2015 at 06:25 PM 0
Share

What do you want to happen to the force over lifetime?

avatar image Mernion · Feb 24, 2015 at 07:07 PM 0
Share

In the unity editor I can edit "force over lifetime" parameter in particle editor. Changing "X" coordinate giving me desired effect. But i cant set fixed "X" coordinate from editor, I need to change it from the game, so I looking for a way to write a script, so i can change it from game, but no idea how I can change this parameter from script..

avatar image karljj1 · Feb 24, 2015 at 07:17 PM 0
Share

I'm not sure I follow. You want the x coordinate to stay the same but the y and z to change over time? Could you do it using the curve setting ins$$anonymous$$d of constant?

avatar image Mernion · Feb 24, 2015 at 08:22 PM 0
Share

I've added a picture with my problem. Top pictures are my ideal representation of what I want from my particle system and bottom one is what I currently have. Problem is - I want to change X coordinate after some delay if my ship is rotating (like on the top pictures), but idk how to do this. World simulation space result does not provide me any delay :(

particle.jpg (225.3 kB)
avatar image
1

Answer by Digital-Phantom · Feb 23, 2015 at 08:08 AM

If you use the built in particle system there is an option to toggle between LocalSpace / WorldSpace. I think its WorldSpace you need (if not choose the other) this will give your particles the effect of moving/swinging around as your objects rotation changes

:)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Particle collider not working 0 Answers

An OS design issue: File types associated with their appropriate programs 1 Answer

Set a range of startSpeed for Shuriken via script 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