Draw a line in forward direction of a object
I am trying to draw a line between the translate.forward direction and a point 20 unit further then the translate.forward point. This is the code I use (I added the LineRenderer component to the object):
 LineRenderer lineRenderer = mHead.GetComponent<LineRenderer>();
 lineRenderer.SetPosition(0, transform.position);
 lineRenderer.SetPosition(1, transform.forward * 10);
This is not working correctly (I think). Since when I use the Debug.DrawRay(...) it gives me another line code:
 Debug.DrawRay(transform.position, transform.forward * 10, Color.red, 0);
Does anyone knows how to do this correctly?
What do you mean by drawing a line between a direction and the direction * 20?
I have updated the question, I hope it is more clear now!
Do you mean you want a line between your current position and 20*facing direction away from your current position? Try this:
 LineRenderer lineRenderer = mHead.GetComponent<LineRenderer>();
 lineRenderer.SetVertexCount(2);
 lineRenderer.SetPosition(0, transform.position);
 lineRenderer.SetPosition(1, transform.forward * 20 + transform.position);
Don't forget to set the color of the LineRenderer.
Answer by Janjanus · Sep 22, 2015 at 02:43 PM
@sys12 suggested to change the code to:
  LineRenderer lineRenderer = mHead.GetComponent<LineRenderer>();
  lineRenderer.SetVertexCount(2);
  lineRenderer.SetPosition(0, transform.position);
  lineRenderer.SetPosition(1, transform.forward * 20 + transform.position);
This worked perfectly! Thanky You @sys12!
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                