Oh sorry yea that’s possible.
To check all parts between the player and the radiated part you could just do a loop where you raycast towards it and if the raycast hits something that isn’t the radiated part, then you add that to a list of parts you’ve hit, and then use that same list in the raycastParams blacklist.
If you wanted the width of the part then you could do a couple of things, but what I’d do in order to measure how much of each part is actually in between the player and radiated part is basically raycast once towards the radiated part, then if you hit something, do a backwards raycast going from the radiatedPart to the character, and for the backwards raycast you should set the raycastParams to whitelist, and only whitelist the part that you hit in the original raycast.
From there you can take the hit positions of the forward and backwards raycast and measure the distance between them, that should calculate how much wall is between you and the radiated part for one of the walls.
Combining the raycast looping with this would look something like this:
function raycastAwayFromRadiatedPart(raycastFilterType,raycastFilterList)
local raycastParams = RaycastParams.new()
raycastParams.FilterType = raycastFilterType
raycastParams.FilterDescendantsInstances = {raycastFilterList}
local rayOrigin = radiatedPart.Position
local rayDirection = HRP.Position-rayOrigin
local raycastResults = game.Workspace:Raycast(rayOrigin,rayDirection,raycastParams)
if raycastResults then
return raycastResults
end
end
function raycastTowardsRadiatedPart(raycastFilterList)
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {char,raycastFilterList}
local rayOrigin = HRP.Position
local rayDirection = (radiatedPart.Position-rayOrigin).Unit*maxDistance
local raycastResults = game.Workspace:Raycast(rayOrigin,rayDirection,raycastParams)
if raycastResults then
return raycastResults
end
end
function tryRaycastTowardsRadiatedPart()
local totalWallThicknessBetweenRadiatedPart = 0
local partsBetweenRadiatedPart = {}
local hitRadiatedPart = false
local hitNothing = false
while not hitRadiatedPart and not hitNothing do
local forwardRaycastResults = raycastTowardsRadiatedPart(partsBetweenRadiatedPart)
if forwardRaycastResults then
if forwardRaycastResults.Instance == radiatedPart then
hitRadiatedPart = true
else
table.insert(partsBetweenRadiatedPart,forwardRaycastResults.Instance)
local backwardsRaycastResult = raycastAwayFromRadiatedPart(Enum.RaycastFilterType.Whitelist,forwardRaycastResults.Instance)
if backwardsRaycastResult then
local dist = (backwardsRaycastResult.Position-forwardRaycastResults.Position).Magnitude
totalWallThicknessBetweenRadiatedPart += dist
end
end
else
hitNothing = true
end
end
if hitRadiatedPart then
print(totalWallThicknessBetweenRadiatedPart)
local wallCount = #partsBetweenRadiatedPart
print("hit "..tostring(wallCount).." parts")
print("radiated part found")
else
print("radiated part not found, most likely out of range")
end
end
Sorry for the messy code, wrote this really quick. It is tested and I’m 99.9% sure it’s completely working. Of course you should always try to pick it apart, figure out how it works, find optimizations, all that. Just remember to look through before copying and pasting basically.
Also made an optimization I wasn’t thinking about before. Instead of using an if statement to check if the player is out of range, just normalize the raycast direction with .Unit then multiply it by the max distance.
Not sure what you’re trying to accomplish with this alone, but from the looks of it, some sort of research game. If you wanted, you could also utilize the raycastResult.Material property and have a check for some of the materials like Enum.Material.Metal or Enum.Material.DiamondPlate, and have those block radiation more than other parts by counting their wall thickness as double or something like that.
Note to anyone who may want to use this solution:
There is an issue where if you parent a part to another, one of the parts will not be detected in the forward raycast, but will be detected in the backward raycast. Be aware of that. My only idea on how to fix this is to set FilterDescendantsInstances to {char}, disable the raycastParams.RespectCanCollide value, then set the .canQuery value for anything you want to blacklist to false. This isn’t the full solution, just look into it if you need to be able to parent parts to one another.