Problem with physics.set_shape()

I’m trying to set the dimensions of a box shape at runtime:

local shape =
{
	type = physics.SHAPE_TYPE_BOX,
	dimensions = self.dimensions
}
physics.set_shape(msg.url(nil, nil, "collider"), "shape", shape)

This documentation shows that I need a type field in the table, however Defold doesn’t recognize any physics.SHAPE_... options. (I’m using the latest version of the editor.)

This documentation strangely doesn’t include the type field. If I remove it from the table, I get the following error:

bad argument #6 to 'set_shape' (number expected, got nil)

…which is weird because there are a maximum of three arguments, not six. The url to the collision object (collider) is correct, and the name of the shape itself (shape) is correct. Here is a snippet of the hierarchy:

Screenshot 2024-05-24 151053

It’s not enough info. Please provide a minimal repro case (a small, isolated project where the issue you are talking about is reproducible). Maybe you’ll find what did you miss.

Because here is my example I’ve just made and it works fine:

set_shape.zip (7.6 KB)

please take a look, and try to compare with your setup

Ah thanks, it did actually work once I included the type field. It’s a bit weird though since the editor doesn’t recognize the shape types:

I’m running Windows 11, Defold 1.8.0, and editor SHA 8dfb2825db0d62dfc910fdcf8c271a005d5edb99.

The shape types are set as “constants” here in script layer of the physics code:

This means that if you iterate _G.physics at runtime you should see them together with all the other functions and constants.

But that is not enough for the editor to know about them, or for the API reference to include them. The code must also have code annotations that we can pick up and use when we generate the API docs and auto-complete for the editor, like these ones for the joint types:

Would you like to attempt a PR to add the shape type constants?

3 Likes

Hey I appreciate you posting the source code for these things. Sure, I’d be glad to try it!

1 Like

This is awesome.

Maybe we can get some better user assisted write ups in the documentation too.

1 Like

I’ve been talking a little bit about this topic here: Contributing to the Defold Repository

@JCash recently added a bunch of new engine source docs here:

I recommend anyone curious about the source code to read through those documents.

I’m not really into the source code thing. There are much better devs for that stuff. But I’m talking about the documentation to make it easier to use defold’s features & APIs. They are accurate, but very technical and some written where it’s clear it was from someone that understands the source code.

It would be cool, if there was a concentrated effort (aka make it easy) for us to update the manual on how to use the features/APIs. Once again what is there isn’t “wrong”, but it’s very high level and technical. A more practical how-to on many of the features would be great. Leveraging the user community would really help.

We welcome contributions to the documentation. All of the documentation is available on GitHub for anyone to improve. Would you like to give it a go?

2 Likes

Yes. Next time I see something that can be simplified I’ll give it a shot.

What link is used for git hub docs?