# Infinite line through two Vecrtor points.

Hi Forum-People ,

I need help with some scriptin’.

So far I have a script that draws a line from point A to point B:

using UnityEngine;
using System.Collections;
public class Linie : MonoBehaviour {
void Update() {
Debug.DrawLine(new Vector3(-5, -2, 7), new Vector3(3, 5, 10),Color.red);
}
}

It works perfectly fine but I need the line to go through those two points and to be infinite on both sides

Thanks for any help in advance

Stakior

I’m not sure if it’s possible, but then again I do not have that much experience.
Do you have to have it infinite, or is it enough that it is shown all across the screen?

If it is enough that the player/camera thinks it is infinite, you can calculate the line from the left side of the camera view edge to point A, and from B to the right camera/view edge.

Else, well, just use really big numbers for the edges?

I tried that, I can’t get the line directly through the Points
It would be better if the line would be infinite though .-.

Well, you could create an equation of the line from A to B, and then calculate it’s position on the positive and negative ends.
You know, y = m*x + n ?
If that’s not possible, then again, have it intercept with the camera view edges (which should have simple linear equations)

Yeah I know that equation, but is it really the same like that ( y=m*x+n) in 3d space ? .-.

Whats wrong with making the lines very long instead of infinite?

Debug.DrawLine(new Vector3(-5000, -2000, 7000), new Vector3(3000, 5000, 10000),Color.red);

Cuz it Needs to be infinite .-.

``````Debug.DrawLine(new Vector3(-5, -2, 7)* Mathf.Infinity, new Vector3(3, 5, 10) * Mathf.Infinity,Color.red);
``````

Does that work?

Debug.DrawRay is infinite, though only in one direction. But you can use two! Just need to get the direction vector for first one then the other.

``````Debug.DrawRay(point1, point2-point1);
Debug.DrawRay(point1, point1-point2);
``````

@ DrSnake No it doesn’t work the line doesn’t even apear anymore

I did not know DrawRay is infinite.
If it really is, find a point between A and B, call it C.
Then, like StarManta suggested, draw from C to B, and C to A, that way it goes both ways.

hey bro.
I didn’t test this out, but I think this will work.
you can multiply mathf.inifinity to the vector

``````Vector2 v1 = new Vector2(2, 2);
Vector2 v2 = new Vector2(-2, -2);

Debug.DrawLine(v1 * Mathf.Infinity, v2 * Mathf.Infinity, Color.red);
``````

I just get the same line, which starts at A and Ends at B

Oh… huh. Sorry. I guess that was a bad assumption on my part.

…Why is Debug.DrawRay not infinite!? A Ray is infinite!

@ StarManta Hey I gave you the coordintes with PointA (-5, -2, 7) and PointB (3, 5, 10) .

Could you help me get These into your script from above ? pliiiiieees