Hey, I’ve been searching for a while, and I really need help. I have no clue how to make a trail smaller with code. In my game, when you pick up a powerup, you shrink. So, I need the trail to shrink along with it. I’m using the trail renderer.
Use TrailRenderer.startWidth, TrailRenderer.endWidth, or TrailRenderer.widthCurve.
Yea I saw those, but I dont know how to use them
Define an AnimationCurve, and then set the TrailRenderer.widthCurve as the animation curve. for example,
public class Script : MonoBehaviour
{
private TrailRenderer trail;
public float widthMp = 1f;
public bool isSmall;
void Start()
{
isSmall = false; // Example bool.
trail = GetComponent<TrailRenderer>(); // Define the TrailRenderer component.
}
void Update()
{
AnimationCurve trailWidth = new AnimationCurve(); // Define trailwidth as an animation curve.
if (isSmall == true)
{
trailWidth.AddKey(0.25f, 0.25f); // Make both values something small so you have a small, consistent trail.
}
else
{
trailWidth.AddKey(1f, 1f); // Otherwise make the trail normal-sized.
}
trail.widthCurve = trailWidth; // Declare that the trail's width curve property is equal to the animation curve we just made.
trail.widthMultiplier = widthMp; // Make the trail's width multiplier the float we made earlier. (pretty self explanatory)
}
}
There’s a little example script I made. Hope it helps
Im going to bed but Ill try that out tomorrow, thanks so much
No problem! You can just drag and drop the script onto an object with a TrailRenderer component and it will work.
Edit: I forgot to mention that changing the float values for the AddKey parts in the if statement will change the keys on the curve. You can tweak these values and keys to ease in/out the width.
cool, appreciate it