RayCast doesn't detect ball

I am making a ray cast because hit-detection is way too unreliable, but the ray cast I create cannot detect the ball I made (the ball has collision groups to only be able to touch the ground and also is network owner to the player but I don’t think those are the errors). Below is the code I’m using to find the ball (it detects everything else)

local raycastParams = RaycastParams.new()
	

	local raycastResult = workspace:Raycast(char.HumanoidRootPart.Position, char.HumanoidRootPart.CFrame.LookVector*100, raycastParams)

	if raycastResult  then
			
		local currentPart = raycastResult.Instance
	print(currentPart)
		
	end
1 Like

Do you have the CanQuery Property of the ball turned off?

Do you have any blacklists or whitelists for the raycast?

CanQuery is not in the properties tab also there is no white and black lists

In the ball’s Properties in the Collision section there should be a Checkbox for CanQuery.

that’s because you have CanCollide enabled, disable the CanCollide property so you can use it, and CanQuery is enabled by default

Couple of things to check:

  • CanQuery property (as mentioned above)
  • Make sure the CollisionGroup property of RaycastParams is set to the correct collision group.
  • If the ball is not a “Part” (ex: “MeshPart”, “UnionOperation”, etc) then check that the CollisionFidelity is set correctly
  • Make sure your testing conditions are right (With the example code, it would be shooting a ray in front of the player’s character) and the ball’s network correctly exists on the client/server the code is being run from.

If none of these fix your problem, I recommend just destroying & redoing the ball/code and then seeing if it works, because I see no logic/syntax problems in your provided code.

How large is the ball? If it was too small, then HumanoidRootPart may be too high for it to be detected. If the ball is not around the same size or bigger than the player, then the ray cast will not hit it.
It might be something you have already confirmed, but I am just telling you in case you have not.

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