Change body shape and(or) it's properties #324
-
Hello! Couldn't find anywhere on the Internet how to change properties of existing shape. I think I'm figured it out, but I'm not sure is it the right approach. TypedIndex originalShape = Sim.Bodies.GetDescription(colRef.BodyHandle).Collidable.Shape;
var shape = Sim.Shapes.GetShape<Box>(originalShape.Index);
shape.Width = opts.Size.X;
shape.Height = opts.Size.Y;
shape.Length = opts.Size.Z;
inertia = shape.ComputeInertia(opts.Mass);
var desc = Sim.Bodies.GetDescription(colRef.BodyHandle);
desc.LocalInertia = inertia; However I don't know how change shape type (for example box to capsule) without completely recreating body. Is it even intended? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Almost! If you changed it to:
then it would be a memory reference.
You can also grab a
If you want to change the shape referenced by a body, you can use |
Beta Was this translation helpful? Give feedback.
Almost!
GetShape
returns a reference to the shape. Since the shape itself is a value type, assigning to a non-ref variable just copies it, so it's no longer a reference to the original memory.If you changed it to:
then it would be a memory reference.
GetDescription
works differently; it builds aBodyDescription
for you, but modifying it will not modify the original because it's just a copy of the data again. Because there is no place in the library where aBodyDescription
actually sits around, it can't return aref
to it. You can useApplyDescription
to set all of a body's properties to match the description.You can als…