You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
When a ray hits two parts, simultaneously, it detects both of them. Or, when a ray hits two parts simultaneously, it adds one of the two and detects the second part in a second ray cast (does not happen).
-
What is the issue? Include screenshots / videos if possible!
Currently, there is an issue with the ray script I have as every time the ray will hit two parts at the same time it will only detect that one is being hit, add that one to the ignored list, and for some reason not detect the other part it hits simultaneously. I would think that after the ray detects the one part it would be cast again (by the script) and detect the second part and keep going. However, that isn’t the case. It just stops for whatever reason at the part that’s hit at the exact same time as the one that will later be added to the ignore list.
Edit: To visualize the scenario, think of two parts spaced slightly apart and the ray aims the in-between spacing of the two parts, resulting in hitting both at the same time.
1 Like
Try casting a new ray(at the same direction) after the hit, including the hit part to the ignore list. This should do the trick for piercing rays.
The thing is, it does that. You would assume that after it hits the one part, the next ray will (with the first part ignored) hit the second part in the way, and keep going, right? But it gets caught up and does not stop, at least in my script.
To stop it after the first pierce, either you would use an incremental variable to read how many hits it has taken and stop casting any new rays after the first hit or a boolean for one pierce only.
The script stops working when it hits/pierces the object that was meant to be hit, that is, desired to be hit. And it does, just not with parts that it hits simultaneously.
Edit: Sorry for the late reply. The part is just completely undetected for some reason, even after the other part was added to the ignore list. I’m not sure why.
What do you mean by stop working? Could you elaborate?
Sorry, that was a bad way of putting it. The while loop finishes.
So, normally, say there are 3 parts that it will intersect (so not going to hit two parts simultaneously) it will go through until the last desired part is hit. In the case of the two parts being hit simultaneously, the first part that is hit is added to the ignore list, hence why I thought the second ray afterwards would hit the other part since it is ignored. That isn’t the case, though. I can’t figure out why.
Would you please provide the script sample out of the entirety? Might help understanding the procedure.
Yea, sure. He’s the script that handles it all.
while #listOfIgnoredHexs ~= #tableOfRayTouch do
local rayOrigin = game.Workspace[startHex].HexTile.CFrame.p
local rayDestination = game.Workspace[hexName].HexTile.CFrame.p
local rayDirection = rayDestination - rayOrigin
local ray = Ray.new(rayOrigin, rayDirection)
local hitParts, hitPositions = workspace:FindPartOnRayWithIgnoreList(ray, listOfIgnoredHexs)
if hitParts then
if string.match(hitParts.Parent.Name, 'Hex') then
if #listOfIgnoredHexs ~= #tableOfRayTouch then
print(hitParts.Parent)
table.insert(listOfIgnoredHexs, hitParts.Parent)
end
end
end
end
Edit: The first part (origin part) is already in the ignore list. Sorry, the code gets messy with the pasting.
Did you find anything? I’m still trying to figure it out but I found nothing.
Edit: Something interesting I should note, if the desired object is beyond the two objects that would be simultaneously hit, the ray will actually get there and hit the desired object, but will not have either of the two parts hit simultaneously recorded.
https://gyazo.com/00a14391924f97abee0a50f5ea322a8c
Can we expand this into broader context to understand the achievement of using the ray?
Pathfinding. I need the hexs to be gathered from beginning to end, connecting for the unit. Obviously, there are other factors to be considered with the pathfinding (e.g., two hexs in on same Z or X have to be considered) but that isn’t a problem right now, this, however, is.
At this point, seeing as I can’t figure anything out, and I can’t find anything to fix it, this may be a ray casting bug.
Well, The reason for it stopping working is that the number of things inside the list of ignored hexs are the same as the table of ray touch.
To fix it you should find a way to make that thing dont happen
Yes, it stops working because the ray isn’t recognizing (see the picture) the hex that it is suppose to recognize, and (see code) there doesn’t seem to be a reason as to why that it ignores it but still is able to travel all the way to the desired hex. It compares listOfIgnoredHexs with tableOfRayTouched, yes, and tableOfRayTouched is already done, that isn’t the problem. The problem is listOfIgnoredHexs, but if the ray hits something, then it should insert it to the list, but, it is not.
Who is the hexpart.Parent? Print it
Which part of the code are you referring to?
if string.match(hitParts.Parent.Name, 'Hex') then
this one is the one im saying.
A model that contains the HexTile part that the ray hit. hitParts is HexTile, and HexTile.Parent is ‘Hex####’. You can see what I mean in the image.
1 Like