PhysicsServer3D.SetShapeData(RID, Variant) Confusion

Godot Version

4.2.2

Question

I’m probably being dumb, but I’m struggling to see how you set data for more complex physics intersection check shapes like Cylinder (Radius and Height) and Capsules (Radius and Height)?

(I use C# mostly and the code below is a first stab at some dynamic collision work - I’ll lose the reflection “else if’ing” and likely switch case it at some stage)

The code:

                Rid shapeRid;
                if (_currentSpawnCmd.spawnCollisionCheckShape3D is BoxShape3D)
                {
                    shapeRid = PhysicsServer3D.BoxShapeCreate();
                    PhysicsServer3D.ShapeSetData(shapeRid, (_currentSpawnCmd.spawnCollisionCheckShape3D as BoxShape3D).Size);
                }
                else if (_currentSpawnCmd.spawnCollisionCheckShape3D is SphereShape3D)
                {
                    shapeRid = PhysicsServer3D.SphereShapeCreate();
                    PhysicsServer3D.ShapeSetData(shapeRid, (_currentSpawnCmd.spawnCollisionCheckShape3D as SphereShape3D).Radius);
                }
                else if (_currentSpawnCmd.spawnCollisionCheckShape3D is CylinderShape3D)
                {
                    shapeRid = PhysicsServer3D.CylinderShapeCreate();
                    PhysicsServer3D.ShapeSetData(shapeRid, (_currentSpawnCmd.spawnCollisionCheckShape3D as CylinderShape3D).Radius);
                    PhysicsServer3D.ShapeSetData(shapeRid, (_currentSpawnCmd.spawnCollisionCheckShape3D as CylinderShape3D).Height); // How can this work as a variant vs Radius?
                }
                else if (_currentSpawnCmd.spawnCollisionCheckShape3D is CapsuleShape3D)
                {
                    shapeRid = PhysicsServer3D.CapsuleShapeCreate();
                    PhysicsServer3D.ShapeSetData(shapeRid, (_currentSpawnCmd.spawnCollisionCheckShape3D as CapsuleShape3D).Radius);
                    PhysicsServer3D.ShapeSetData(shapeRid, (_currentSpawnCmd.spawnCollisionCheckShape3D as CapsuleShape3D).Height);// How can this work as a variant vs Radius?
                }

It depends on the Shape You can check the source code to know what each Shape needs: godot/scene/resources/3d at master · godotengine/godot · GitHub

For example:

That’s it then… A Dictionary parameter. I did think I could look at the CPP source code but thought better of it and so stuck to a simple “size” box. Thanks for that, I guess the documentation could be updated to help the less CPP inclined :stuck_out_tongue_winking_eye:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.