-
Hi! I'm working on implementing Jolt support in our game engine, and I'm noticing that there're no setters for e.g the BoxShape or SphereShape. In our engine we do have a need for e.g Just wondering if there's a reason for this, or if you just haven't thought of doing that? Looked into it a bit and from what I could tell Jolt doesn't build convex hulls for box shapes or sphere shapes (I may have missed it if you are doing that). Either way just wanted to check if there was a reason for that not being supported, or if the intended method for doing this is to re-create the shape from scratch 🙂 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello, The fact that there aren't any setters is on purpose. In specific cases it would be harmless to have them, e.g. if your body uses a simple sphere shape, it's not colliding with anything and you don't care about the mass/inertia you could easily change its radius. If however your sphere is part of a compound shape and you change its radius then the bounding volume information of the compound shape will be incorrect. Also its calculated center of mass will be incorrect and because a body stores not its position but its center of mass position, this means a change of center of mass of the shape actually implicitly changes the position of the body. Finally, if the body is in the vicinity of another object the collision caches will need to be updated after a radius change. The official way of changing shapes is to use the BodyInterface::SetShape functionality. You'd create a new sphere with the radius you desire and this function will take care of the center of mass / the contact caches and the mass for you. Note that in general you have to be careful with changing shapes on the fly. If you make a shape bigger than it was, and the object was wedged between other objects, it may cause that body to tunnel through the objects it was wedged between. |
Beta Was this translation helpful? Give feedback.
Hello,
The fact that there aren't any setters is on purpose. In specific cases it would be harmless to have them, e.g. if your body uses a simple sphere shape, it's not colliding with anything and you don't care about the mass/inertia you could easily change its radius.
If however your sphere is part of a compound shape and you change its radius then the bounding volume information of the compound shape will be incorrect. Also its calculated center of mass will be incorrect and because a body stores not its position but its center of mass position, this means a change of center of mass of the shape actually implicitly changes the position of the body. Finally, if the body is in the vicini…