Blockcast not detecting properly?

Hi, I am writing custom physics with custom collisions, I am using a blockcast for the collision detecting but the blockcast doesnt detect anything even when it seemingly should?

local function visualiseBlockCast(startPosition, size, direction, collisionParams)
	local result = workspace:Blockcast(
		CFrame.new(startPosition),
		size,
		direction,
		collisionParams
	)

	local visualiser = workspace:FindFirstChild("visualiser")

	if not visualiser then
		warn("visualiser part not found in workspace")
		return
	end

	visualiser.Position = startPosition + direction
	visualiser.Size = size

	if result then
		visualiser.Color = Color3.fromRGB(0, 255, 0) 
	else
		visualiser.Color = Color3.fromRGB(255, 0, 0) 
	end
end

function BoxCollider:checkCollision(predictedPosition)
	local collisionParameters = RaycastParams.new()
	collisionParameters:AddToFilter({self.physicsBody.part, workspace.visualiser})

	local direction = predictedPosition - self.physicsBody.part.Position
	direction = util.clampVector(direction, 0.5, math.huge)
	
	visualiseBlockCast(self.physicsBody.part.Position, self.size, direction, collisionParameters)

	local result = workspace:Blockcast(
		CFrame.new(self.physicsBody.part.Position),
		self.size,
		direction,
		collisionParameters
	)
	
	return result
end```
1 Like

I’m not entirely sure, however I think that the problem is caused by the blockcast scraping the ground when your object is standing.

When you start any kind of cast inside of an object, the object is ignored for the cast, so in your case the ground gets ignored.

You could, for example, try to move the blockcast slightly in the inverse move direction (if the object is standing still, then that would be the inverse if gravity pulling down aka up).
That way, if there was anything that the cast would’ve overlapped with on the ground, it would no longer do so.

2 Likes

Does this only go for shape casts or for raycasts aswell (Ignoring if it starts within it) and if so, what is an alternative to the blockcast?

Yes, this ignoring behaviour goes for every kind of cast.
As I mentioned, one way you could do this would be to start the blockcast up a bit back to give it space between the ground.

You could also try to make an extra normal raycast from the center of the object for an extra check in case the blockcast was touching the ground.

Or, if you have resources to spare and complex geometry (large concave pieces in which the object can go), you could for example split the one big blockcast into 9 (3x3 blockcasts or even 27 with a 3x3x3 blockcasts) smaller blockcasts in order to get more accurate data. But this approach is most likely unneccesary if you don’t have complex geometry like I mentioned. This option still needs the raycasts to start up higher tho.

1 Like