Hey there.
I am having an impossible time recreating this effect for my 2D platformer:
I’d like to create a sprite trail just like in the example but I can’t seem to figure it out; I can almost create the effect for just one still sprite with particles, but to have it trail after the sprite animations seems way out of my grasp. I’ve tried trail and line renderer but both those don’t create a trail from the sprite sheet, only their own little separate effect.
Ok, previous solution works for me fine, but not as good as I want, because it updates every trail part texture continuously.
Here’s another small example I’ve wrote for couple of minutes:
using UnityEngine;
using System.Collections;
void Start()
{
InvokeRepeating("SpawnTrail", 0, 0.2f); // replace 0.2f with needed repeatRate
}
void SpawnTrail()
{
GameObject trailPart = new GameObject();
SpriteRenderer trailPartRenderer = trailPart.AddComponent<SpriteRenderer>();
trailPartRenderer.sprite = GetComponent<SpriteRenderer>().sprite;
trailPart.transform.position = transform.position;
Destroy(trailPart, 0.5f); // replace 0.5f with needed lifeTime
StartCoroutine("FadeTrailPart", trailPartRenderer);
}
IEnumerator FadeTrailPart(SpriteRenderer trailPartRenderer)
{
Color color = trailPartRenderer.color;
color.a -= 0.5f; // replace 0.5f with needed alpha decrement
trailPartRenderer.color = color;
yield return new WaitForEndOfFrame();
}
Add this code to your character’s script on GameObject with Animator component.
The code is pretty simple and works perfect for me. I wrote it in hurry, so it can be refactored and optimized:) For example you could reuse trailPart gameobjects instead of instantiating and destroying it everytime (object pool technique), etc., depends on you;)
Well this is some pretty magnificent script you wrote for me; so pardon my while I show some cringe-worthy noobness.
The ghost doesn’t appear to be be affected by my Flip () function. so while it looks great heading in the correct direction. if i turn around my sprite the ghost doesn’t turn as well
Alright , updated the code to our new attempt but no luck. Seems like these ghosts just don’t want to flip! Script still runs but acts unchanged.
I will also haphazard this guess(which might be completely wrong since I know very little);
The Hierarchy is instantiating the ghosts as “New Game Object”, and I feel like maybe it’s supposed to create them as trailPart for the “foreach” function to work.
I promise these scenes aren’t empty. They work on my second machine if I go into unity File>Open Project>Open Other>Character Move Tutorial Without Rigidbody>Select folder.
Guess the whole project is required for the scenes inside it to work