I cant figure out why I can't see this instanced scene, requesting help

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

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.

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.

eons | 2017-05-11 13:21

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.

Robster | 2017-05-12 05:36