Create a vector3 point in a direction between 2 moving objects?

I can’t find how to do this, even tried google to page 5 but no results :frowning:

The thing i need is, I need to create a vector3 point in world space thats in the direction of to objects.
Object1, Object2 I need to direction from object1 to object2, i got that with:

var heading = Object1.transform.position - Object2.transform.position;
var distance = heading.magnitude;

I created a debug line to show the result:
alt text

Good that works, However as both points will be moving all the time, lets check that:
alt text
If i move Object2 it works fine, But if i move object1 I get this:
alt text

Messing up the hole direction.
Again i do all this to create a point past Objecty2, as i target for object2 to move to.
I might be doing it all wrong, any tips are welcome!

If you want the direction from Object1 to Object2 in world space, the correct formula is target - origin:

Vector3 direction = Object2.transform.position - Object1.transform.position;
float distance = direction.magnitude ;
Debug.DrawRay( Object1.transform.position, direction ) ;

ok, that works a lot better indeed, but how do i create a point past object2

As in Object2 will be inrange of object1 and so moves away from it,.


Vector3 direction = Object2.transform.position - Object1.transform.position;
float distance = direction.magnitude;
Debug.DrawRay(Object1.transform.position, direction);

Debug.DrawRay(Object2.transform.position, direction * 2,;