for only instantiate one object, trying to create a circumference of scenes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Raikish

I’m trying to create a circumference with some sprites.

I wrote something like this:

extends Node2D

var radius
var center_screen = Vector2()
var shape_size
export var num_shapes = 5
var next_angle # in radiants
export (PackedScene) var Shape

func _ready():
	center_screen = get_viewport_rect().size / 2
	global_position = center_screen

	radius = center_screen.x / 3
	shape_size = (2 * PI * radius) / num_shapes
	next_angle = (2 * PI) / num_shapes

	for i in num_shapes:
		var shape = Shape.instance()
		call_deferred("add_child" , shape)
		shape.position.y = radius
		global_rotation = global_rotation + next_angle

But when i execute looks like only one shape is created, any help? Could be anything with the call_deferred?
https://gyazo.com/44cb09d36ae9446593dcecf42733d20b

:bust_in_silhouette: Reply From: SIsilicon

Changing the global rotation of the scripted node alone won’t change the apparent rotation and position of the one being made. You would need to do something like this.

var shape = Shape.instance()
call_deferred("add_child", shape)
shape.position = Vector2(sin(global_rotation), cos(global_rotation)) * radius
shape.rotation = global_rotation
global_rotation += next_angle

Really thank you, seems like i’m a little bit sleepy with my maths :slight_smile:

Raikish | 2018-12-12 18:26

You can do
for i in num_shapes:
if the num_shapes it’s a number

Raikish | 2018-12-12 18:34

I see. I’ll note that. The docs should really include that.

SIsilicon | 2018-12-12 18:45