# Sampling Animations for Smooth Weapon Trails?

I’ve been trying to figure out how to get nice smooth weapon trails instead of the jagged mess you naturally get, but never seemed to hit that point of figuring it out.

Then I remembered one of the devs of Pocket RPG, Evan Greenwood posting this in the showcase thread to explain how he got the smoothness:

Me, not being much of a programmer is trying to figure out what he meant by this, where would I start. I tried contacting for info but I havent received a response since. So, anyone with knowledge of this, or how to do it, can shed some light?

Thanks.

So, lets say you have a sword, and you want to add a script to it that creates a visible trail. What you need is a list of about 256 upper and lower points. You can actually treat it just like a vehicle’s tire tred script. Get a point at the top, and get a point at the bottom and that would give you a series of points to tinker with. you will need something like this:

``````class trailPoint{
var upperPoint : Vector3; // in world space
var lowerPoint : Vector3; // in world space

var lastPoint : int; // index of the last point (-1 means no last point)
var startTime : float;
var duration : float;

function trailPoint(uPoint : Vector3, lPoint : Vector3, last : int, dur : float){
upperPoint = uPoint;
lowerPoint = lPoint;
lastPoint = last;
startTime = Time.time;
duration = dur;
}

function isUsed(){
return startTime + duration > Time.time;
}

function GetUpper() : Vector3{
var age = (Time.time - startTime) / duration;
return Mathf.Lerp(upperPoint, (upperPoint + lowerPoint) / 2, age);
}

function GetLower() : Vector3{
var age = (Time.time - startTime) / duration;
return Mathf.Lerp(lowerPoint, (upperPoint + lowerPoint) / 2, age);
}
}
``````

Then cycle through the 256 points each LateUpdate and create a quad for each trail point with a lastPoint and returns true from the isUsed function.

You will want to capture this data about every 0.1 seconds. (this leads to about 25 seconds of total capture.) Do this in a coroutine. You can even have a pole to tell you if you should be capturing data.

First of all, thanks for the response. Second, so this is basically rewriting a Weapon Trail script right? Before I do anything else, I’ve been looking at the Weapon Trail script that is on the Asset Store, is this basically what it does, or does it need more tweaking to get the smoother trails seen in the Pocket RPG thread?