Help finding Position based on Origin, LookVector, and Distance

Been trying a lot of different ways to get this, but I am not great at CFrame math , hopefully someone knows.

I need to find a world position based on an origin position where I have the LookVector and a distance to move along that LookVector.

So, lets say:
I have a part at 0, 0, 0
I have an arbitrary LookVector expressed as a Vector3
I have a distance, lets say 20 studs

How can I find the new position using those? Thank you!

Quite easily, thankfully (assuming you want to move in the direction of your LookVector). A LookVector is just a normalized vector, which means it has a magnitude (think “distance”) of 1. Because of this, you can just multiply that LookVector by the desired distance (e.g. 20) to get the position offset. You then add this position to your starting point (e.g. 0, 0, 0).

local partPosition = somePart.Position
local lookVector = someLookVector
local distance = 20

local offset = lookVector * distance
local newPosition = partPosition + offset

-- Or the two above lines into one:
local newPosition = partPosition + (lookVector * distance)
8 Likes

You rock buddy, thanks for that. I wish this example was on the wiki!

1 Like