- Home /
Fixed distance from point
Hi,
I need to generate a point from another fixed point that has a fixed distance. The point must be the closer point to the player. So If I have a start point 0,0,0 the nearest point to the player that is 10 feet distant from 0,0,0.
You want a point that is aways 10 feet forward the player?
Answer by Zerot · Sep 25, 2012 at 02:19 PM
let's say point a is the origin, point b is the player and d is the distance you want.
Then the resulting point is p = a+(b-a).normalized*d
(b-a).normalized should return a vector that is the direction from a towards point b. we normalize it to make it length 1.
We multiply it with d so it gets the right length. And we add it to point a because we want its position to be relative to a.
hey you're right ... I think that's what he's asking
Good one.
Nice one man this works :D the only problem that my dist must be negative to be on the right side (near the player). If "d" is positive the point is correctly aligned with the character but on the other side of the starting point :D
Can you edit? so for the other guys that will see this answer :D
Your answer
![](https://koobas.hobune.stream/wayback/20220613081455im_/https://answers.unity.com/themes/thub/images/avi.jpg)