Issue with raycast result


Blue - Direction
Green - The final result, the position of the raycast

Despite the fact that the Direction is aimed strictly straight ahead, the position appears in a completely random place, as if.

Front of this Part
OneSideCollision.rbxl (51.4 KB)

are you firing the raycast immediately after you spawn in?

Here’s the fixed raycast function:

local function Raycast()
	
	local Origin	= Character.PrimaryPart.Position;
	local Direction = (Part.Position + Part.CFrame.LookVector * 2 - Origin);
	
	local Parameters = RaycastParams.new(); do
		
		Parameters.FilterType				  = Enum.RaycastFilterType.Blacklist;
		Parameters.FilterDescendantsInstances = { Character };
		
	end
	
	local Raycast = workspace:Raycast(Origin, Direction, Parameters);
	
	if Raycast and Raycast.Instance then
		
		MakeItOpen(false, tostring(Raycast));
		
	else
		
		MakeItOpen(true, "Raycast was not successfull!");
		
	end
	
	VisualizeRaycast(workspace.RaycastPart, workspace.RaycastPositionPart, Origin, Part.Position + Part.CFrame.LookVector * 2, Raycast);
	
	return;
	
end

Your issue was that you were using raycasts wrong, the 2nd parameter is supposed to be the direction of where the ray goes, not the position of where the ray goes.

1 Like

Thank you so much! I will take note of my mistake

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