0 votes

Hi all,

First of all, this is my code:

#the ball scene we will instance
var scene = load("res://ball.tscn")

for ball in get_tree().get_nodes_in_group("balls"):
    #get the position of each of the balls
    var ballPos = Vector2(ball.get_pos().x+30, ball.get_pos().y+30)
    var newBall = scene.instance()
    newBall.set_pos(ballPos)
    get_node("/root/gameLevel").add_child(newBall)
    print("adding balls")
    newBall.add_to_group("balls")
    #random direction
    newBall.set_state(STATE_MOVING)
    print("ball added: ", str(newBall), " at ", str(ballPos))

So essentially I have a powerup, I touch it, this code is triggered, ball is meant to appear (Currently at 30 pixels to the right and below the current ball just to test).

Now I can see in the print statement that a newball is created, it has a unique name, it has a postition. The ball is never visible though. I just can't figure it out.

Can anyone see anything glaringly obvious? I feel like I'm at my ends. a few days of looking at it here and there and it's time to ask.

Any help MUCH appreciated...

EDIT: turns out it's the STATE line. I'll investigate further and report back for anyone in the future.

in Engine by (810 points)
edited by

To see if was correctly added, check the remote inspector and look at the position values of the new ball.

Maybe you need to use global position instead.

It turns out it was my state machine. I was able to get it to show.

Then, the next problem was, when it was in the moving state it was checking to see if a ball collision occurred. If it did, then it reflected to the opposite direction.

Unfortunately it was colliding with the ball as it was being created, had no speed or direction and just sat there.

So I create the new ball just outside of the collision boundary of the existing ball and it works! Took me nearly all day to figure that out. Man!

Thanks for the comment, it got me looking in the correct direction for a solution.

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 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 webmaster@godotengine.org with your username.

Categories