0 votes

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())
        add_child(newBlood)
        switchBloodSize = 1

    elif(switchBloodSize == 1):
        newBlood.scale(Vector2(0.5,0.5)) //This part is my problem
        print("Blood size: ", newBlood.get_scale())
        add_child(newBlood)
        switchBloodSize = 0

    newBlood.set_pos(Vector2(100,100))
    rotate(rotationAdd)

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 Engine by (101 points)

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?

Hi Zylann, http://imgur.com/a/PlUW8 . As you can see, Blood is Rigidbody2d and Sprite contains a simple PNG image. No code or anything has been changed besides that.

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.

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.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.