Not getting any Raycast Result

Tried running this however only returns no result.

uis.InputBegan:Connect(function(inp, gpe)
	if gpe then return end
	
	if inp.KeyCode == Enum.KeyCode.X then
		local mousePos = mouse.Hit.Position
		 
		local origin = humRP.Position
		local direction = (origin - mousePos).Unit
		local params = RaycastParams.new()
		
		params.FilterDescendantsInstances = {char, ignore}
		params.FilterType = Enum.RaycastFilterType.Exclude
		
		local rayCastResult = workspace:Raycast(origin, direction, params)
		
		connection = runService.Heartbeat:Connect(function(dt)
			if rayCastResult then
				local part = Instance.new("Part")
				part.Parent = ignore
				part.Position = direction
			else
				print("no result")
			end
		end)
		
	end
end)

You are only raycasting once when X is pressed. Is that intentional?

Yeah, that’s intentional — I’m trying to make a projectile fire when X is pressed, and I’m using this as a way to start learning raycasting.

The ray will only be cast to the length of direction, so you need to multiply it by some value, right now it’s 1 which will probably not reach anything.

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