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

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

in Engine by (100 points)

1 Answer

+1 vote
Best answer

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
by (3,938 points)
edited by

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

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

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

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.