- Home /
Line Renderer Question
Using a line renderer, how can I make it draw a line from the object that the script is attached to, to straight out in front of it for an endless distance?
I know how to use the line renderer but have been having some issues with trying to do the above, so some code help with this would be appreciated.
I'm using Unity Free and UnityScript.
I'm making a laser with this, and I have only 10 days left to do it.
Answer by ArkaneX · Sep 11, 2013 at 07:47 PM
You can use below code. But regarding the 'endless distance' - do you really need it to be endless, or do you want it to be 'quite far from start'? I don't know if endless is ever possible - I have never thought about Unity coordinates limits, but I guess some large distance will be enough. And if you really need it to never end, then you have to think of some solution to trick the user.
Anyway - sample code:
var lineRenderer : LineRenderer;
function Awake()
{
lineRenderer = GetComponent.<LineRenderer>();
}
function Start ()
{
lineRenderer.SetPosition(0, this.transform.position);
}
function Update ()
{
lineRenderer.SetPosition(1, this.transform.position + this.transform.forward * 1000000);
}
This code makes it go forward in world coordinates though, the object will be turning along all axis according to the users input. So it needs to shoot out along the objects forward.
Do you know how to do this?
Hi @ArkaneX, am new to line renderer. Can I use your code to draw line by assigning x y z of device motion, just like a graph? Please if you can help.
thanks in advance. cheers
Your answer
Follow this Question
Related Questions
Warped lines with line renderer 0 Answers
Using line render to draw a graph 0 Answers
How to draw two lines at the same time that keeps overlapping each other? 1 Answer
Lightning Using A Line Renderer 0 Answers