Raycast only hitting certain faces

local uis = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local character = plr.Character or plr.CharacterAdded:Wait()
local hum = character:WaitForChild("Humanoid")
local humroot = character:WaitForChild("HumanoidRootPart")

local function raycast()
	
	local raycastParams = RaycastParams.new()
	raycastParams.FilterType = Enum.RaycastFilterType.Exclude
	raycastParams.FilterDescendantsInstances = {character}
	
	local raycastOrigin = humroot.Position
	
	local raycastDirection = Vector3.new(0, 0, 1.25)
	
	local raycastHit = workspace:Raycast(raycastOrigin, raycastDirection, raycastParams)
	
	if raycastHit then
		print(raycastHit.Instance)
	end
end

uis.JumpRequest:Connect(raycast)

Does anyone have an idea on how I can fix it? It’s only hitting one face of a part.

You didn’t really describe your problem with much detail, but I can tell you’re probably trying to fire a raycast out from the character’s position in the character’s direction.

To do that, you’d need to use the LookVector property of the root part’s CFrame. The raycast direction is a vector relative to the world which will mean it will always move in the Z direction which is why it only hits one face.

local raycastOrigin = humroot.Position
local raycastDirection = humroot.CFrame.LookVector * 1.25
-- get the direction of the root part (which is length 1) then multiply the length by 1.25

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