Why make things difficult? Life doesn’t need to be difficult.
I started my project to create a beautiful comet-like trail, and had plans to spend a week or more on it. In the end, however, I realized a nice looking trail can be created simply by combining two Unity components, with a little nifty scripting:
Trail Renderer
Particle System
The trail will be used to show the shot path of a basketball, so I want it to show until a make or miss is definite. This is where the particle system comes in.
I first create a prefab to hold the particle system, trail renderer, and ball trail script.
For the particle system, I use a simple star texture for the material:
The initial setup:
Next I randomize the size of the particles:
increase the emission rate, and base emission off distance, so the rate is constant no matter the speed of the ball:
Also emit using a shape:
We then fade the particles over time, using color over time option. In order to select the alpha channel, you must click the top tab/arrow:
Next, we change the particle color to white, and add these options:
For the trail, adjust the time depending on desired trail length, and make start width larger then end width. Then, adjust the colors to gradually decrease alpha in order to create a fade effect:
Finally, to add some polish, we fade the trail out using the TrailRenderer options startWidth, endWidth, and time:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
public void TurnOff () { if (!destroying && shot) { destroying = true; particleSystem.Stop (); // transform.parent = null; StartCoroutine (FadeOut ()); } } IEnumerator FadeOut () { int numParticles = particleSystem.GetParticles (particles); Color testColor = particles [0].GetCurrentColor (particleSystem); while (trail.startWidth > 0 || testColor.a > 0) { float amount = Time.deltaTime / fadeOutTime; trail.startWidth -= amount*5f; Mathf.Clamp (trail.startWidth, 0f, trail.startWidth); trail.time -= amount*5f; Mathf.Clamp (trail.time, 0f, trail.time); for (int p = 0; p < numParticles; p++) { testColor = particles [p].GetCurrentColor (particleSystem); testColor.a -= amount; particles [p].startColor = testColor; } particleSystem.SetParticles (particles, numParticles); yield return null; } Destroy (this.gameObject); } |
And BAM!
i have a 2d dot texture when i add it to my bow it show a wide line moving with it how i fix it
I’m not sure what you mean by a ‘2D dot texture’. Could you elaborate?
i want to show my previous shoot what should i do
like angry birds