Ray can only hit 1 side of parts

I’m trying to make a wallrun but the ray I’m using can only hit 1 side of a part. I haven’t been able to find anything about it. Everything is currently done in a local script.

Code:

local plr = game.Players.LocalPlayer
local chr = plr.Character or plr.CharacterAdded:Wait()
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(I,G)
	if G == false then
		if I.KeyCode == Enum.KeyCode.Space then
			local RP = RaycastParams.new()
			RP.FilterType = Enum.RaycastFilterType.Blacklist
			RP.FilterDescendantsInstances = {chr}
			
			local ray = workspace:Raycast(chr.HumanoidRootPart.Position,(chr.HumanoidRootPart.CFrame * CFrame.new(2,0,0)).Position,RP)
			workspace.RayPart.CFrame = chr.HumanoidRootPart.CFrame * CFrame.new(2,0,0)
			if ray and ray.Instance then
				warn("HIT")
			end
		end
	end
end)

Rays only return the part they hit first, and the normal of the surface first intersected. So you can’t get the other side unless you cast another ray.

The second argument to Raycast is a direction, you’re giving it a position. Change this line to:

local ray = workspace:Raycast(chr.HumanoidRootPart.Position, chr.HumanoidRootPart.CFrame.RightVector * 2, RP)
1 Like

thanks a lot. I somehow didn’t realize that until now