This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Now I make a game that ball will merge to another ball.
like Ball2 collide with Ball2 will merge to Ball_4.

When the Ball2 make collide it will call code in Ball2 to merge and add Ball4 instance to spawner, But code in Ball2 call 2 times I want it to call just one time

here the Ball_2 code if you want, Thank you all :D

extends RigidBody2D

var merge = preload("res://Ball_res/Ball_4.res")

func _ready(): # release ball at mouse position
    var mouse_position = get_global_mouse_position()
    if(mouse_position[0] >= -470 and mouse_position[0] <= 470) and (mouse_position[1] >= -300 and mouse_position[1] <= -250) :
        translate(Vector2(mouse_position[0],0))
        pass
    pass

func _on_Ball_2_body_entered(body): # merge ball
    if "Ball_2" in body.name :
        var ball_instance = merge.instance()
        ball_instance.set_name("Ball_4(Clone)")
        Global.merge_position = position
        get_parent().add_child(ball_instance)
        queue_free()
        pass
    pass
Godot version 3.2.3
in Engine by (21 points)
edited by

1 Answer

0 votes

Now I found.
The answer is just made ball send a global variable to Autoload.gd and let Autoload sen variable to the main scene.

by (21 points)
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.