Looking for a good method to make a part have a ray's length and CFrame

Hey there.
Looking for a good method to make a part have a ray’s length and CFrame that is hopefully not deprecated.

I have looked up a few, but they are rather deprecated or give limitations.

Let me know what you personally use, any help is appreciated.

Here is the function!!

1 Like

If you have your ray, position it at the ray origin + half the direction using a CFrame that has look vector in the same direction, and then size it to the Magnitude of the direction.

The Ray class isn’t deprecated btw (hence why Camera:ScreenPointToRay still exists). It’s only Workspace:FindPartOnRay and it’s siblings that are deprecated in favour of WorldRoot:Raycast

So you can happily use Rays and use the Ray.Origin and Ray.Direction properties.

3 Likes

Alright that worked fine, tysm.

For anyone that needs it, here is the function i made.

local function CastBeam(ray)
    	local CenterPoint = ray.Origin + ray.Direction/2--Center 
    	local beam = Instance.new("Part")--Beam
    	beam.Parent = workspace.Projectiles
    	beam.Anchored = true
    	beam.CanCollide = false
    	beam.BrickColor = BrickColor.new("Gold")
    	--Actually important
    	beam.CFrame = CFrame.new(CenterPoint,ray.Origin)--CFrame
    	beam.Size = Vector3.new(.1,.1,ray.Direction.magnitude)--Size
    end
4 Likes