Spherecast not detecting a object

With 2 objects, and sphere casting between these 2 objects, it only registers an obstacle if it’s far away enough from the obstacle the results vary with different radius

Expected behavior

It should register a collision even at close range, place file is linked below with the script inside of the model

local A = script.Parent.A
local B = script.Parent.B

while true do
	local Result = workspace:Spherecast(A.Position,5,B.Position-A.Position)
	if Result then
		A.BillboardGui.TextLabel.Text = "Detected hit"
		A.BrickColor = BrickColor.Red()
	else
		A.BillboardGui.TextLabel.Text = "No hit"
		A.BrickColor = BrickColor.White()
	end	
	task.wait()
end

Spherecast Bug.rbxl (45.1 KB)

The documentation states an intersection does not occur if the sphere initially intersects with the part.

2 Likes

Is there any reason for this behavior?

Raycasting doesn’t have this behavior

Raycasting does have this behavior. If a ray starts inside a part, that part won’t get detected.

This is because there’s no sane way to represent the contact point in that case. We’re considering a return-all-hits shapecast that gives initial intersections, which would fix this case.

10 Likes

Otherwise initial objects around the part of interest would be hit. For example if you had a player on the ground and he shot a bullet (implemented with spherecast) upwards it would intersect with the player and the ground (well, if the radius was large enough), but turning their canquery’s off would be troublesome if you wanted to for instance add bullet holes and the ground cant be queried, you’d be in a bit of trouble. (And, turning off the ability to hit the players character wont go so well for a gun…) There would also be lots of possibilities to intersect if there were lots of initially intersecting parts. And not to mention it would be impossible to determine an explicit intersection point & normal. As stated above, too, raycasting does indeed portray a similar version of this behaviour albeit less extreme.

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