How to get CFrame from workspace:Raycast()?

  1. What do you want to achieve? I want to get the CFrame from the RaycastResult of workspace:Raycast()

  2. What is the issue? Mouse.Hit can be used to get the CFrame from the Mouse’ Ray, but i want to use the CFrame from workspace:Raycast()

the raycast script i made:

local Camera = workspace.CurrentCamera
local RayLength = 9223372036854775807
local RayResult
local ignoreList = {}

-- Raycast Params
local RayParams = RaycastParams.new()
RayParams.FilterType = Enum.RaycastFilterType.Blacklist

game:GetService("RunService").RenderStepped:Connect(function()

	local CameraCFrame = Camera.CFrame
	local CastedRay= workspace:Raycast(CameraCFrame.Position, CameraCFrame.LookVector * RayLength, RayParams)

	RayResult = CastedRay.Position

end)

1 Like
local Camera = workspace.CurrentCamera
local RayLength = 9223372036854775807
local ignoreList = {}

-- Raycast Params

local RayParams = RaycastParams.new()
RayParams.FilterType = Enum.RaycastFilterType.Blacklist
RayParams.FilterDescendantsInstances = ignoreList

game:GetService("RunService").RenderStepped:Connect(function()

	local CameraCFrame = Camera.CFrame
	local CameraAngle = CameraCFrame.LookVector
	local CastedRay = workspace:Raycast(CameraCFrame.Position, CameraCFrame.LookVector * RayLength, RayParams)

	CastedRay = CFrame.new(CastedRay.Position) * CFrame.Angles(math.rad(CameraAngle.X), math.rad(CameraAngle.Y), math.rad(CameraAngle.Z))
	
	print(CastedRay)

end)
2 Likes

seems to work perfectly with my code, thanks!

1 Like

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