I have a projectile that is similar to a bouncing cannonball. I need to be able to plot a dotted line to predict the path of the projectile.
Since the path needs to take physics into account, I figure it’s easier if I actually lob an identical invisible projectile with a Trail Renderer attached. That kinda works well enough for me, except that I can’t figure our how to get a material that can get the Trail Renderer to plot the path as a dotted line.
Just to provide an actual answer, here’s a script that will make a dotted line path for a rigidbody object using Vectrosity. The lineMaterial should use a texture with a dot in it.
var lineMaterial : Material;
var maxPoints = 500;
var ballPrefab : Rigidbody;
var force = 16.0;
private var pathLine : VectorLine;
private var pathIndex = 0;
private var pathPoints : Vector3[];
function Start () {
pathPoints = new Vector3[maxPoints];
pathLine = new VectorLine("Path", pathPoints, lineMaterial, 12.0, LineType.Continuous);
var ball = Instantiate(ballPrefab, Vector3.zero, Quaternion.Euler(300.0, 70.0, 310.0)) as Rigidbody;
ball.useGravity = true;
ball.AddForce (ball.transform.forward * force, ForceMode.Impulse);
SamplePoints (ball.transform);
}
function SamplePoints (thisTransform : Transform) {
var running = true;
while (running) {
pathPoints[pathIndex] = thisTransform.position;
if (++pathIndex == maxPoints) {
running = false;
}
yield WaitForSeconds(.05);
pathLine.maxDrawIndex = pathIndex-1;
Vector.DrawLine (pathLine);
Vector.SetTextureScale (pathLine, 1.0);
}
}