So recently I have been experimenting with the feature shapecasts. For something I am making, I need the blockcast to detect the center of a flatsurface first. I don’t know a lot about how the raycast algorythm works. But from what it seems like, is that it casts tons of rays rather then 1, starting from the edge of the blockcast and then it moves along the x,z axis until it has casted rays across the whole part.There is a very good chance that I am completely wrong in this assumption but this is what my experimenting seems to tell me.
The issue is when I cast a blockcast torwards a flat surface, instead of raycastresult.Position to be the center of the targetPart, it is the edge of the targetpart. Is there perhaps a way in the scenario that the blockcast is casted on a flatsurface that it returns the center position instead of the edge?
This code casts a blockcast with the same size as the targetpart, and casts directly above the center of the targetpart
The bluepart is what I assume should be the size and position of the shapecast
The red ray is a visualisation of the initial position of the blockcast. And goes torward raycastResult.Position
local targetPart = game.Workspace.targetPart
local originCFrame = targetPart.Position + Vector3.yAxis*10
local size = Vector3.new(10, 1, 10)
local direction = -Vector3.yAxis
local raycastResult = Workspace:Blockcast(CFrame.new(originCFrame), size, direction * 10)
visualiseRay(targetPart.Position + Vector3.yAxis*10, raycastResult.Position)
Blockcast demonstration
I have managed to get this expected result by using spherecasts instead, reason why spherecasts get the center first is because the bottom center of the sphere will touch the targetpart first meaning it will detect the center first and return that as the hitpos. The reason I don’t want to use spherecast is because I believe it should be possible with blockcast, and I think it would be more effficent to do this with blockcasts then spherecasts, because of the less triangles etc.
local originCFrame = game.Workspace.testing.Position + Vector3.yAxis*10
local size = Vector3.new(10, 1, 10)
local direction = -Vector3.yAxis
local raycastResult = Workspace:Spherecast(originCFrame, 5, direction * 10)
visualiseRay(game.Workspace.testing.Position + Vector3.yAxis*10, raycastResult.Position)
Spherecast demonstration(What i want)