I'm doing this 2D (top-down perspective :D).
Basically the 'main' scene is a StaticBody
with a script which allows me to rotate it and the following children:
- a
Sprite
node;
- an instance of another scene (the moving character).
The code for the child scene is the following, currently attached to an Area2D
node (since the move
function stops the sprite while I'm rotating its parent):
extends Area2D
var speed = 50.0
onready var start_pos = get_viewport().get_rect().size / 2
var movement = Vector2()
var direction = Vector2()
func _ready():
set_global_pos(start_pos)
set_fixed_process(true)
func _fixed_process(delta):
var cur_pos = get_global_pos()
direction = start_pos - cur_pos
movement += direction.normalized() * speed * delta
set_global_pos(movement)
What happens is that the child node rotates around its pivot (not around the parent's) and just keeps going to the center.
What I want is to change the child's position according to the rotation (just imagine you put a rubber on a rotating DVD :p), while it's still moving towards the center of the screen.
Am I overthinking this? Should I change approach?