I’ve been fiddling with trying to do a hitbox that performs box:GetTouchingParts()
It’s been working great in my other games, but in this new game, it does not detect certain parts that are within a model that have CanCollide true, Anchored false, and Archivable true. I’ve made the hitbox very big and the part itself big as well (both greater than 5 studs in each axis).
The hitbox always detects the character model body parts, but fails to detect a custom model that is built at runtime. As soon as I put the parts in the workspace, or just clone the parts and put them in the workspace instead of directly in the model, they can be detected by the hitbox. It’s a very peculiar problem and I’d like to know if there are any problems with parts built at runtime and collisions?
Again, the issue here is GetTouchingParts(). It is not detecting supposedly valid parts in a model, and i want to know if there are patterns to look for
EDIT: here is a simple .rbxl file that shows the problem: car-test-hitboxes.rbxl (152.5 KB)
If you go to my serverscriptservice and find the User module, and go to the #addPart method, you will find TEST1. I set it to false to show the error, which is where it tries to weld to nearby parts in the model, and it fails by only detecting the chassis and seat, not any of the parts built on it.
In the game, whenever you build, you will see a red hitbox that checks for nearby parts, and the output console will print all the touching parts of that box. Currently it detects none of the custom parts that are in the car model.
Although this does fix the problem in the test place, I replicated the code to my actual game and it does not detect the parts again.
Your solution is also confusing to me, because all you did was move the part to the place it is supposed to be welded to, although that should not matter in terms of checking for other colliding parts.
The check in the box that the part is not being welded to itself also is not related to the GetTouchingParts method, so I’m still confused.
I’m going to dig around more to see what I changed in my game to make the test place.
I think it might actually be a bug with how GetTouchingParts works with welds. Because all the parts don’t have a predefined CFrame and are only assigned a CFrame indirectly via weld.C1, it might be ignored by the collision method. One odd solution is to do this check on the client only, which surprisingly works.
Fiddled around with it more, now its just working on some tests and others it doesn’t, even if I change nothing between them. I am almost completely sure its some engine quirk that is stopping the GetTouchingParts() detection from occuring.
EDIT:
It seems to more specific to also detection on ANCHORED welded parts, where normal anchored parts are always correctly detected by GetTouchingParts().
I made another small test just with one CanCollide true anchored part and an unanchored CanCollide true part welded to the anchored part. I tried doing GetTouchingParts() on the welded unanchored part, but it was not detecting. I think this is the pinpointed bug at its finest.
I can’t post on the studio/engine bug reports, but I believe this is something that needs to be fixed for collisions.
Thanks for the report. There’s definitely a bug here but it’s not related to the change to how unanchored objects welded to anchored objects behave. That change only slightly changed the way this bug manifests.
It appears if you move an unanchored part at all after welding it to an anchored part (either by the weld moving it or setting the CFrame property on the unanchored part directly) our broadphase doesn’t appear to update the position of that part correctly. Because of this FindPartsInRegion3 or GetTouchingParts won’t correctly find the part there. I’ll file a ticket and we’ll look into this later.
For now you can work around this by setting the position of the part to it’s destination before creating the weld. If you do this it appears to work correctly. I added part.CFrame = frame after part.Parent = self.carModel in the script you mention and it worked.
Yes it works sometimes, but at other times it still does not weld correctly, or simply immediately destroys the weld. Again, the test place here works but when I transition to my actual game and use the exact same script, it either fails outright or fails most of the time. I can probably give you the link to the game or teamcreate with you to show you what I mean.
Thanks again for the response, hopefully this is fixed soon.
EDIT:
Found out why it does not work sometimes, its because I load in a build with saved welds, therefore I didn’t consider the part.CFrame hack that I must apply to all loaded in parts. So my particular problem is solved!