How to get a Vector3 position originating from a point, facing towards another point, but past 2 studs?

I have one position and I need to get a Vector3 position a certain distance farther than another position, in the direction between the two positions. It’s a confusing question, so I’ve made a diagram to illustrate it. Any help is appreciated!

Basically. When you position a part on the newposition in roblox. It’ll go straight into it, so if you divide it by two. It’ll get the middle point.

local NewPosition = (NewPos - Origin) / 2

You can also use lerping to get a certain percentage.

local NewPosition = Origin:Lerp(NewPos, 0.5)

Hope that helped buddy.

You could calculate the direction from the first position to the second position using subtraction and normalization (using the Unit property), then move the desired distance in that direction from the second position by multiplying the direction by the distance and adding it to the second position. This way, you get a new position farther along the same line.

Here’s an example using this logic:

local part1Position = Vector3.new(1, 1, 1)
local part2Position = Vector3.new(4, 1, 4)

local distance = 2 -- The distance (adjust as needed)

-- First calculate the direction
local direction = (part2Position - part1Position).Unit

-- Then calculate the new position
local newPosition = part2Position + direction * distance

print("The new position is:", newPosition) -- Would be about (5.4, 1, 5.4) in this example
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.