-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change bounds creation to use colliders instead. #2942 #2945
Change bounds creation to use colliders instead. #2942 #2945
Conversation
I was just playing with this installed today and I noticed the bounds are still including the realfuels' engine plumes. I'm not sure why those are "colliders" but it may be that it's not enough to check for triggers. Maybe it's also necessary to filter some colliders out by layer number? |
This is an interesting problem. A plume, for realism, would need colliders. But this gets into the realm of "flavors" of collision. One certainly wouldn't want the same collision rules for smoke as for a 3kt engine. Is there some kind of mask that tells a collision mesh what it is allowed to collide with? I'm gathering that the plume is perhaps considered a part of the craft and so brings its collision mesh along with when trying to determine bounds. If not the layer number one would have to find something different about the plume meshes to filter them out by for sure and I'm curious what that ends up being, but if the plume is considered a craft part, maybe filtering it out on the part level prior to looking at meshes might work. And I don't even know if that makes sense |
Okay, so the plumes are NOT the problem. |
I think this is the issue: The documentation for Mesh.bounds in Unity says this:
The Unity documentation for Collider.bounds says this:
The Mesh bounds is in local space, which we then find the 8 corners of it and transform that into World space afterward. The Collider bounds starts out already in world space, which means: (A) It's wrong to do that transform on them, and (B) They'll have extra space around the corners because world axes don't align with the part's orientation. It looks like there is a solution but it's messier than just a drop-in replacement. It goes like so: Get the Type of the Collider. Colliders come in 4 types: Sphere, Capsule, Box, and Mesh. If the type is MeshCollider, then use the code already written for Meshes, but you have to get the If the type is |
Thanks for looking in to this and identifying what exactly was wrong, I'll update this PR to include the suggested fix. |
I have implemented the suggested solution. Some notes though:
|
Good question. I think throwing an exception here is probably inappropriate because it's not something the user can fix in their script. Maybe just a SafeHouse.Logger.Log() message rather than an exception. Then we can see it is happening but it won't break the script execution. Maybe when it's an unknown collider we just say it's "not there" and make it zero size. (or very very small size since a zero-size bounds may cause some of our values to be zero-length vectors making them have no defined direction, causing possible math errors elsewhere.) Edit: Better idea - When the type of collider is unknown, just skip over it like we would for a "trigger" collider. Still give that SafeHouse.Logger.Log message, but treat it as if that collider wasn't even present. That's probably the "safest" in terms of protecting the code from crashing. |
Okay I changed it to log and skip. |
I started playing with this installed today and now it seems to be working properly. Good Job! |
Changes the way a part's Bounds are computed from using the part's meshes to using colliders.
Colliders that are triggers are excluded.
Fixes #2942
See #2905 for additional information.