Multiple trails following my character

I want to spawn mutliple trails, they must all follow my moving character, playing with the particle system and the trail renderer I realized that you can only spawn one trail, or multiple trails but originating from particles.

Since I want the multiple trails to follow my character and not particles, I can’t use trails spawning from particles. What should I do to spawn mutliple trails that follow a moving object?

I don’t fully understand fully why you can’t use particles for this? If you make the particles follow the player (local simulation space, and parented to the character), then the trails will also follow.

1 Like

Yea ok my bad, thanks

Good luck :slight_smile:

You can also hide the particles and show only the trails by setting the Render Mode in the Renderer Module to None.

1 Like

Cool thx!

One last thing if you don’t mind: Can I use a sprite sheet for animations on the trail renderer?

You can, but the issue is that Particle System’s Texture Sheet Animation module doesn’t work on particle trails. For that you need a separate script to scroll the trail material.

Save the following code as “AniamtedTexture.cs” to your project folder and add it to your trail object.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AniamtedTexture : MonoBehaviour {
    [Tooltip("Material to be scrolled. If none is assigned, it will look for trail material of particle system first.")]
    public Material mat;
    [Tooltip("Texture identity of the material to be scrolled. Exact identity can be found in the shader property.")]
    public string texture = "_MainTex";
    [Tooltip("How the UV of the texture is divided. Value smaller than 1 means the UV is repeated which requires 'Wrap Mode' of the texture to be 'repeat'.")]
    public Vector2 tileDivision;
    Vector2 tiling;
    [Tooltip("Scrolling interval in second.")]
    public float scrollTime = 0.1f;
    float t;
 
    void OnEnable() {
        if (mat == null) {
            var psr = GetComponent<ParticleSystemRenderer>();
            mat = psr.trailMaterial;
            if (mat == null) {
                mat = GetComponent<Renderer>().material;
            }
        }
        reset();
        tiling.x = 1f / tileDivision.x;
        tiling.y = 1f / tileDivision.y;
        mat.SetTextureScale(texture, tiling);
        mat.SetTextureOffset(texture, new Vector2(0, mat.GetTextureOffset(texture).y + tiling.y));
    }
    void Update() {
        t += Time.deltaTime;
        if (t > scrollTime) {
            mat.SetTextureOffset(texture, new Vector2(mat.GetTextureOffset(texture).x + tiling.x, mat.GetTextureOffset(texture).y));
            if (mat.GetTextureOffset(texture).x >= 1) {
                mat.SetTextureOffset(texture, new Vector2(0, mat.GetTextureOffset(texture).y + tiling.y));
            }
            if (mat.GetTextureOffset(texture).y >= 1) {
                mat.SetTextureOffset(texture, new Vector2(mat.GetTextureOffset(texture).x, 0));
            }
            t = 0;
        }
    }
    void OnDisable() {
        reset();
    }
    void reset() {
        mat.SetTextureScale(texture, new Vector2(1f,1f));
        mat.SetTextureOffset(texture, new Vector2(0f,0f));
    }
}
2 Likes

Nice, thanks for the script ifurkend, much appreciated!
I’ll try it right away :wink:

The script works! I’m just not sure how to properly exploit it yet, gotta make some good textures to go with it.
Did you ever use that script yourself ifurkend?

I took this fx sheet online to try it out: http://rswhite.de/dgame5/tutorial/images/explosion.png
Here’s the result: https://drive.google.com/open?id=0B7SRXWCJcuQtYjI5WV9hT3FUNTA

It’s pretty awful like that, if I come up with something good, I’ll post here again to show you the result.

I don’t usually scroll or flip texture for my trails. If I am making a jet like trail, I will just emit a trail of particles (emission rate over distance) instead of using trails module/renderer.

The only instance which animated trail is applicable would be making a electric plasma trail to scroll your plasma flipbook texture.

1 Like

I’ll try it the plasma trail out ifurkend.
I originally wanted to achieve a tentacle-like trail, where the start of the trail originates from the box (character) and then spreads/fans out more and more towards the end of the trail.

The problem with trails is that I don’t think such behaviours can be achieved. Here’s the closest I got: https://drive.google.com/open?id=0B7SRXWCJcuQtQkZpdUlKRk1velU (the noise was a little too high)
As you can see, in order for the end of the trail to be spread out, the particles need first to be spread out since the beginning of the trail (which I don’t want in this case).

I want that effect to be based on movement, so I thought trail was the way to go but it seems to be a dead end.

I looked at particles before trying out the trail way, however looking at a few tutorials I saw people don’t seem to bother doing effects that would follow erratic movements (because their effects are linear in nature).
For example: This tutorial

(watch the first 20s) does a projectile with a core texture, if this texture was to be rotated to follow some entity’s movement, it would surely look quite silly because it’s a big sprite rotating instead of a trail.

The core texture: Imgur: The magic of the Internet

I don’t know if I’m clear on what I’m trying to achieve, is this something that’s generally hard when creating effects or am I missing something?

The texture for composing the particle-trail (without trails module/trail renderer) you need is just a round one. Don’t attempt any “long-tail” texture if your projectile is gonna turn.

1 Like

I wouldn’t call that a dead end exactly. Although you didn’t succeed in the effect you were going for - I can totally see the beginnings of a Villain Carnage type effect here. It’s pretty cool imo.
Carnage from Spiderman - :rage: