Search code examples
game-physicsresolutiongodot

Godot physics resizing my sprites at runtime


I am still new to Godot 4.1. I am trying to set up a simple sprite with a .png texture to be affected by gravity. I set up a Node2d, then a RigidBody2D as the Node2d's child. I added a CollisionShape2d with a RectangleShape as a child to the Rigidbody2D. Finally, I added a Sprite2d as a child of the CollisionShape2D. The sprite is affected by gravity (it falls down) when I run the game, but the sprite is being resized to at least three times its original size. The original image is 294 * 711. All the nodes have their transform in (0,0) and their scale in (1,1), except the parent, the Node2D which has scale of (0.12,0.193). Why is my sprite getting resized at runtime and how can I fix it? Any help appreciated.


Solution

  • RigidBody2D manages there own transforms, which overrides anything you set in the editor. So in Editor it looks like everything is way smaller, because you set the scaling of the root pretty low, but when you run it, the scaling from the parent gets ignored.

    I tried your configuration and if you look at the remote tree, the rigidbody should have a scaling around 8.33 (in my case), which results in everything inside the rigidbody having their normal size.

    So set back the scaling on your Root Node2D to 1,1 (if it's only reason was to shrink the sprite) and edit the scale of the sprite directly.

    As examples I add the scales I get in the remote debugger.

    Scales at runtime, when I use your settings (Node2D Scale 0.12/0.12 everything else at 1/1): Node2D 0.12/0.12 Rigidbody2D 8.333/8.333 everything els 1/1

    Scales at runtime, when I use following settings ( Everthing 1/1 but Sprite Scale 0.12/0.12): Everthing 1/1 but Sprite Scale 0.12/0.12