How can you get a point on a direction,which is defined by 2 Vector 3s

Hi to all.
Im making a RTS Game an ive encountered a problem.

I have the position of two units(Vector3)and i want to find the point with one unit closer to the units positions from the middle point;

I know how to calculate the middle point, but HOW do i calculate the points one unit towards the units position.

I`m trying to find point1 and point2;

Given two Vector3 name unit1 and unit2:

var dir = unit2 - unit1;  
var middle = unit1 + dir * 0.5;
var point1 = middle - dir.normalized * dist;
var point2 = middle + dir.normalized * dist;

Where ‘dist’ is the distance from the middle.

This is simple.

Let’s say you have your vector from Unit1 to Unit2 :

 Vector3 unit1To2 = unit2.transform.position - unit1.transform.position;

You can have the length of that vector by doing this:

 float vLen = unit1To2.magnitude;

You can have the unit vector (of length 1) by doing the Normalize operation:

unit1to2.Normalize();

You can find the middle point doing so, assuming unit1to2 has been normalized.

Vector3 middlePoint = unit1.transform.position + (unit1to2 * vLen /2.0f);

You can also directly have point 1 and 2 by doing this:

Vector3 point1= unit1.transform.position + (unit1to2 * ((vLen /2.0f) - 1.0f ));
Vector3 point2= unit1.transform.position + (unit1to2 * ((vLen /2.0f) + 1.0f ));

For this kind of problem you really have to familiarize with vector math, magnitude (length), Normal vectors, etc.

Doing a RTS without this knowledge will be impossible, but I wish you luck learning :slight_smile: