I need help getting a position 20 studs in a direction

I would like to find a way to get the Position 20 studs in a direction of my choice. In this case (0,0,0), the starting Position will be the Green parts Position.

local GreenPart = script.Parent
local RedPart = Instance.new("Part")
RedPart.Parent = game.Workspace
RedPart.Color = Color3.new(1, 0, 0) --Makes part red
RedPart.Position = Vector3.new() -- where I need to find 20 studs in the direction (0,0,0) which is an Orientation.
RedPart.Anchored = true

~You could change the CFrame, like this:

RedPart.CFrame = CFrame.new(-20, 0, 0)

Only works in some cases.
I’m not going to give you the exact code, so just mess around with CFrame.

I just need some way to make a ray cast result position if the ray cast does not hit anything

You can use the LookVector of the parts CFrame and multiply it by the offset of how many studs you want.

local Part = -- define path
local OffsetSize = 20  -- in studs

local NewPosition = Part.CFrame.LookVector * OffsetSize

If you would like to do different directions then you can look into the RightVector, UpVector, and using negative offsets for directions not listed.

here is some code I tried writing but as you can see in picture the part moved to the right
image

RedPart.Position = CFrame.new(GreenPart.Position,game.Workspace.Part2.Position).LookVector * 20-- Part2 is the see frew part in pictor

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