Suppose we had a ray inside of a part. We cast that ray, and it would eventually leave the bounds of that part. I need to know the position of where this happens. Is there a type of ray that does what I described ?
Yes, possibly. So I don’t think you can cast a ray outside of the part facing the direction of the point we want to raycast to. Something else from the shape, so maybe an overhang like in the image, could perhaps be in the way of the ray.
This is the simplest solution to your problem I could think of that doesn’t involve tons of math:
Make a huge part that covers the entire map of your game, name it air if you want. Make it invisible and anchored, and turn CanCollide and CanTouch to false but leave CanQuery to true
Make a raycastParams and add only the air part to the FilterDescendantsInstances table
Set the FilterType of the raycastParams to Enum.RaycastFilterType.Include
Remember to include the raycastParams to the workspace:Raycast
This way the raycast will only be able to hit the air part, giving you the position of its bounds
Drawback to this system: You’ll need to remember to exclude the air part in other raycasts else they will always keep hitting it
If the air part covers the entire map, so it also covers the part i’m casting insdie from, then all rays with these parameters will immediately hit airpart when casted…
By the way, what do you need this for? If it’s for a hitbox you can use workspace:GetPartsInPart() inside of a loop (I recommend RunService loops) to get all the parts that are inside of your part no matter how it’s shaped
I need this to measure the width of a shape at a certain direction. Look at the original diagram, the ray is coming out of the center of the part. You’ll see what i’m using that for shortly, i’m still sorting things out. I’ll let you know
Here is something hacky I put together to find the size of an instance given an axis.
local function returnAxisWidth(instanceToCalculate: Instance, axis: Enum.Axis)
local clonedInstance = instanceToCalculate:Clone()
local createdModel = Instance.new("Model")
clonedInstance.Parent = createdModel
local _, size = createdModel:GetBoundingBox()
clonedInstance:Destroy()
createdModel:Destroy()
return (size[axis.Name])
end
print(returnAxisWidth(workspace.Baseplate, Enum.Axis.X))
(this size is not always accurate, it is just an approximation)
The original thing I proposed with “raycasting air” is impossible it feels like and I didn’t continue
So that’s why i’m raycasting outside, from both sides, now