How to scale down (decrease size) of an instanced Node/Scene?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Qws
:warning: Old Version Published before Godot 3 was released.

I’m trying to decrease size of instanced RigidBody2D scene through code.

With “scale()” method I’m trying to decrease the size of the image/sprite that’s attached to the RigidBody2D. The problem is, it’s not working.

No matter how much I try to scale down, the size of the blood drop circle remains the same.

Why is this?

This is my example code.

const blood_druple_scn = preload("res://Scenes/blood.tscn")

func spawnBlood():
	var newBlood = Blood_druple_scn.instance()
	rotationAdd = rotationAdd + 30
	if(switchBloodSize == 0):
		set_scale(Vector2(2,1)) //This part is my problem
		print("blood size: ", newBlood.get_scale())
		switchBloodSize = 1
	elif(switchBloodSize == 1):
		newBlood.scale(Vector2(0.5,0.5)) //This part is my problem
		print("Blood size: ", newBlood.get_scale())
		switchBloodSize = 0

As you can see I have 2 different If conditions each with different scale() size. Sadly they are both remain the same size even tho I gave different values to each of them.

Strange part is, it does print that the scale values has been altered. So I guess Blood instance isn’t visually changing.

In the first if, you are scaling the parent, newBlood itself will have an unmodified scale (but the parent will affect it). In the second if you do it on newBlood directly, so you should see a change in your print.
I tried these and it worked for me.
What is blood.tscn? Does it contain only a Sprite or is it more than that?

Zylann | 2016-12-23 19:54

Hi Zylann, Blood = Rigidbody2d. And Sprite contains PNG image of a circle. - Album on Imgur . As you can see, Blood is Rigidbody2d and Sprite contains a simple PNG image. No code or anything has been changed besides that.

Qws | 2016-12-23 20:22

Ok I got a repro… that’s weird, but I’m not sure RigidBodies like being scaled by themselves or from their parent (as in most physics engines), you should scale the sprite itself rather than doing that on the RigidBody2D.

Zylann | 2016-12-23 20:29

If I remember well, the physics engine does not like the scaling of bodies, if you need that, scale/resize the shapes and the visual representations instead.

eons | 2016-12-24 14:55