Question by
JS101 · Mar 23, 2019 at 11:54 PM ·
mathpositioningvector3 operations
Calculating a Vector3 position waypoint
Using the image as an example, I'd like to calculate the vector3 (in green), which is the intersection of a line between my player and target, at a required distance of 1 away from the target.
untitled-2.png
(51.0 kB)
Comment
Answer by Hellium · Mar 24, 2019 at 12:40 AM
public Vector3 GetClosestPointFrom( Vector3 start, Vector3 target, float distanceFromTarget )
{
Vector3 directionFromTarget = (target - start).normalized;
Vector3 point = directionFromTarget * distanceFromTarget;
return point;
// Or, shorter syntax
// return (target - start).normalized * distanceFromTarget
}
Answer by JS101 · Mar 24, 2019 at 02:10 PM
Thank you @Hellium, you've guided me in the right direction but I may have not properly asked my question.
I used the following formula (variation of yours) which seems to work perfectly:
point = ((startPosition - targetPosition).normalized * distanceFromTarget) + targetPosition