Why wont my raycast get anything that isnt right infront of it?

Hey, I have an issue where my raycasts wont go any farther than maybe 0.1-0.2 studs. Do you know why this is happening?

also RaycastLocation is a part:
{73DF6750-D5F1-4DA2-ADF4-E774C4E6CEBE}

and is located here:
{DFB7503F-A46E-4089-8F6E-0CE7017929A5}

Heres my current code (Server script):

local raysettings = RaycastParams.new()
		raysettings.RespectCanCollide = true
		
		local Raycast = workspace:Raycast(script.Parent.RaycastLocation.Position,script.Parent.RaycastLocation.CFrame.LookVector,raysettings)
		print(Raycast)
		
		if Raycast then
			local distance = (script.Parent.RaycastLocation.Position - Raycast.Position).Magnitude
			local p = Instance.new("Part")
			p.Anchored = true
			p.CanCollide = false
			p.BrickColor = BrickColor.new("Bright blue")
			p.Size = Vector3.new(0.1, 0.1, distance)
			p.CFrame = CFrame.lookAt(script.Parent.RaycastLocation.Position, Raycast.Position)*CFrame.new(0, 0, -distance/2)
			p.Parent = workspace
			
			game.Debris:AddItem(p,10)
		end

Any idea why this isnt working?

The magnitude of a look vector will always be 1, and the raycast uses the magnitude of the direction vector (in this case the look vector) to determine how far it can go. Try multiplying the look vector by some value, such as 500 (for 500 studs) and see if it fixes your issue.

1 Like

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