Move towards an object

How do I set the distance of an object relative to another such that the direction between the object remains the same?
I have two objects with a line between them in a certain direction. How do I keep that direction same but change the distance between the object.

Find that direction as a Vector2 or Vector3 (subtract the position of one from the position of the other) then get the magnitude (length) of the line and the unit direction (Normalized). With this you have a vector and distance. You can add/subtract this (vector * change-in-distance) to the position of one of the objects. Alternately add half the change-in-distance to both objects.

If one is chasing the other though, you can simplify this further but you didn’t state that so not sure. Your question is quite general.

This worked for me. Thank you.

1 Like