Getting Points On A Line Between 2 Vectors

Hi Guys,
How can you get the coordinates in a line between 2 points?
e.g. suppose I have 2 points and want to get a vector3 every x units in a straight line from 1 to the other, how would I go about this?

The purpose is so I can draw a path by putting textures down at the points along the line between the 2 points (Not sure if this is the right way to do it or not ?).

Once I’ve had a bit more practice, I’ll make fancier curved paths, but for now I need to stick to the simple bits (Presumably what I end up learning from this post would still be applicable).

Okay, time to take a trip back to middle-school maths :sunglasses:

First, say we have two vectors, A and B

Vector3 a;
Vector3 b;

You’d first want to get the vector between the points:

Vector3 lineWeWant = b-a;

Now, divide the vector by the amount of points you want (say, x points) and then run that through a for-loop:

int x = 23; // I WANT 23 POINTS
GameObject pointPrefab; //some random prefab

for (int i =0; i <x; i++){

Instantiate (pointPrefab, a + (lineWeWant/x * i), transform.rotation);

}

Hope this helps :stuck_out_tongue:

1 Like

ahhh, you’re a star, thank you very much.
I know this is probably something I learned in school (I was almost too embarrassed to post the question) but I couldn’t find a simple answer with my googleFoo.

There was 1 more thing that I’d like to know.
How can I supply a Vector3 and determine whether or not it is somewhere along the line between 2 points?

Can you point me to any resources where I can do some additional reading?

never mind, I found a great resource here:
http://wiki.unity3d.com/index.php/3d_Math_functions

I think the “IsLineInRectangle” method should take care of my needs.

Took a quick glance, looks like it should. If not, feel free to PM me - I’ve just done the topic at school so its definitely fresh in my mind XD