I'm writing a simple Space Invaders clone (the '78 version) but I have no idea how to move the aliens.&lt;br /&gt;This is my scene:&lt;br /&gt;<img alt="k-I4WeoSk2P9Ti21j77CXXlB9NJy0hEljk3kjqqnjT4dl0size1600x1200size_mode3" src="https://photos-1.dropbox.com/t/2/AACweMaLTpq_RfuoC_KWO9K7-FIoIQr33juRp5gCkpsHZw/12/219380198/png/32x32/1/_/1/2/Senza%20titolo-1.png/EKW4_6QBGOYlIAIoAg/k-I4WeoSk2P9Ti21j77CXXlB9NJy0hEljk3kjqqnjT4?dl=0&amp;size=1600x1200&amp;size_mode=3" title="Image: https://photos-1.dropbox.com/t/2/AACweMaLTpq_RfuoC_KWO9K7-FIoIQr33juRp5gCkpsHZw/12/219380198/png/32x32/1/_/1/2/Senza%20titolo-1.png/EKW4_6QBGOYlIAIoAg/k-I4WeoSk2P9Ti21j77CXXlB9NJy0hEljk3kjqqnjT4?dl=0&amp;size=1600x1200&amp;size_mode=3">&lt;br /&gt;&lt;br /&gt;And this is my scene tree:&lt;br /&gt;

&lt;br /&gt;&amp;nbsp; &amp;nbsp; Node2d&lt;br /&gt;&amp;nbsp; &amp;nbsp; ---Enemies (Node2)&lt;br /&gt;&amp;nbsp; &amp;nbsp; ------Alien1&lt;br /&gt;&amp;nbsp; &amp;nbsp; ------Alien2&lt;br /&gt;&amp;nbsp; &amp;nbsp; ------Alien3&lt;br /&gt;&amp;nbsp; &amp;nbsp; ------AlienN&lt;br /&gt;

&lt;br /&gt;&lt;br /&gt;And this is the part of the code where i work with the aliens:&lt;br /&gt;

&lt;br /&gt;if alien_time &amp;gt; 1:&lt;br /&gt;&amp;nbsp; &amp;nbsp; for alien in get_node(&amp;quot;Enemies&amp;quot;).get_children():&lt;br /&gt; <a rel="nofollow" target="_blank">#move</a> alien and check the position&lt;br /&gt;&amp;nbsp; &amp;nbsp; alien_time = 0&lt;br /&gt;else:&lt;br /&gt;&amp;nbsp; &amp;nbsp; alien_time += delta&lt;br /&gt;

&lt;br /&gt;&lt;br /&gt;I would like to move all the aliens to the right until the reach the red line then they go down and then to the left until the red line and they have to repeat this until they collide with the green line.&lt;br /&gt;I'm not sure how to do this,I can't get the last alien position because if the alien get killed it won't work.&lt;br /&gt;I could get the "Enemies" node position and check if is near the red line or not.&lt;br /&gt;Any idea on how to make this work?

I would do it something like this: [img width=750 height=320]http://i.imgur.com/Eypzlm8.jpg[/img]On the parent of all your enemies have an area2D, and in the world put an area2D on either side of the screen where you want it to turn around. When the enemy box overlaps the trigger, call a function on the enemy box that tells it to move down and reverse direction.

[quote author=Ross link=topic=15742.msg17280#msg17280 date=1470154811]I would do it something like this: [img width=750 height=320]http://i.imgur.com/Eypzlm8.jpg[/img]On the parent of all your enemies have an area2D, and in the world put an area2D on either side of the screen where you want it to turn around. When the enemy box overlaps the trigger, call a function on the enemy box that tells it to move down and reverse direction.[/quote]Thank you! This was really helpful!But what if aliens get destroyed? The enemy box will resize based on its children?

[quote author=MrToast link=topic=15742.msg17284#msg17284 date=1470170495]Thank you! This was really helpful!But what if aliens get destroyed? The enemy box will resize based on its children?[/quote]Ah . . . no. You would have to resize the box yourself if you wanted it to change. OK, you&#039;ll need to do a variation on that method then. I assume you already have some collision set up for each of your enemies, either a body or an area. So just make the side triggers cover the whole side of the screen. Then set it up so if any enemy overlaps the trigger, it fires the function to reverse direction. That way it doesn&#039;t matter what enemies there are, they&#039;ll just keep going until one of them enters the trigger. Probably the easiest way to make that function call is to use a group. Whatever node (or nodes) is in charge of moving your enemies, put it in a group &quot;enemy_controller&quot;. Then the trigger node can just get_tree().call_group(0, &quot;enemy_controller&quot;, &quot;switch_direction&quot;). And the enemy controller has the switch_direction() function that does whatever it&#039;s supposed to do. That way you don&#039;t have to store references and make sure they still exist, blah blah, all that stuff. By the way, are you moving all your enemies individually? If I&#039;m thinking right, all the enemies will move in the same exact way, so you should just have to move their parent node right?

You can get it the bounding box to resize rather easily. When an enemy dies, have it emit a custom signal and connect it to a resize() method on the bounding box.[code]signal diedvar alive = truefunc _ready():&nbsp; &nbsp; connect(&quot;died&quot;, get_parent(), &quot;resize&quot;)func die():&nbsp; &nbsp; alive = false&nbsp; &nbsp; emit_signal(&quot;died&quot;)&nbsp; &nbsp; queue_free()func get_bounds(): # This will be used later&nbsp; &nbsp; return get_node(&quot;Sprite&quot;).get_item_rect()[/code]For the bounding box, you&#039;ll want to ultimately generate a Rect2 that encompasses all the invaders. Luckily, every CanvasItem node supplies one and Rect2 has a handy merge(Rect2) method.[code]func resize():&nbsp; &nbsp; var new_size = null&nbsp; &nbsp; for c in get_children():&nbsp; &nbsp; &nbsp; &nbsp; if c.alive:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if new_size == null:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new_size = c.get_bounds()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new_size = new_size.merge(c.get_bounds())[/code]

Oh, that merge function is cool, good to know.

6 years later