Finding offset from direction while keeping orientation?

Currently, I’m trying to find a way to get an offset from a direction while keeping its orientation.

Example:
raycast example 1

How would I achieve this?

1 Like

You need an axis to offset it from.

You can use CFrame.lookAt to generate one

Local axis = CFrame.lookAt(Vector3.new(), direction)

local right vector = axis.RightVector

Yes, but how would I make an offset from the original direction? For example, have it go up like 2 more studs

This is how to get a random offset from direction

local originVector = game.Workspace.PartT.CFrame.LookVector -- Origin Vector

	local offset = CFrame.new(game.Workspace.PartT.Position, originVector + game.Workspace.PartT.Position) -- Get a cframe with the lookvector facing the origin vector.
	
	offset = offset * CFrame.Angles(math.rad(math.random(-17,17)),math.rad(math.random(-17,17)),0) -- get a random angle
	local direction = offset.lookVector -- this gets the random direction

	function createP(pos)
		local part = Instance.new("Part")
		part.Position = pos
		part.Parent = game.Workspace
		part.Anchored = true
		part.CanCollide = false
		part.Size = Vector3.new(0.1,0.1,0.1)
		part.BrickColor = BrickColor.new("Really red")
		part.Name = "joe"
		return part
	end

	createP(direction)