Game Object scale and Collision Object (physics)

Hello!
Today i started learning how do physics work within Defold.
Everything was great, until i ran into an issue related to Game Object scale and subsequent Collision Object. I had two sprites (16x16 and 32x8), which i used in two Game Objects. Since both sprites are tiny, i used scale (x5) on both of Game Objects.

The next thing was to simply add Collision Objects(and basic shapes to them) to both Game Objects. While adding shapes i resized them so they would cover whole sprite:

The problem is: Defold doesnt scale shapes within its Gui when scale is applied in Game Object(in opposition to sprites, on which Game Object scale applies instantly in interface). So, while i thought it was the right way to use scale on the shape itself(so it would cover the sprite), it was a critical mistake to do. When i launched the project i got “sinister physics”. Thanks to that topic, i was able to find the problem using “Physics debug”.

In the end i set shape dimensions according to sprites - 16x16 and 32x8. Everything worked as intended then. Physics debug showed ideal shapes. But within Defold interface the shapes are little 16x16 / 32x8 boxes, while sprites are scaled x5.

I dont know if it’s intended to be like that or not. I read the whole physics manual and wasn’t expecting to get a such a problem.

Actually it does. But remember that Defold is a 3D engine and we have support for both 2D and 3D physics (selected in game.project Physics section). When you scale a game object you must scale it in all three dimensions (x, y and z) for the editor to apply the scale. The editor will always use the smallest of the 3 scale values. At runtime the 2D physics ignore the z-value of the scale.

(We could perhaps be smarter about this in the editor and check game.project if physics is set to 2D or 3D)

1 Like

Yep, i see now. It shows the intended scale right away, when i set Z dimension in Game Object. It was kinda confusing since you dont really use depth in 2D (other than positioning things on screen). It made little sense to me to set Z scale of the object in 2D project, so i didn’t touch it.

Thanks for the reply. It really helped me out :slight_smile: