I need a child node to have a little delay when I rotate the parent node

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

I have a sprite that has to have a little delay when its parent node rotates, the problem is that I don’t know how to do this, to set the sprite to stay the same and then rotate smoothly until it is the same as the parent

Hmm tricky one… Seeing how the sprite is a child of the parent I think when the parent is rotated the child is rotated along side of it via the engine code. This code would do it if the sprite wasn’t a child:

var rotation_speed = 15.0
var my_sprite = get_node("Sprite")
func _physics_process(delta):
    # replace RIGHT with whatever direction your sprite normally faces
    var target_rotation= Vector2.RIGHT.rotated(global_rotation)
    var current_direction = Vector2.RIGHT.rotated(my_sprite.global_rotation)
    my_sprite.global_rotation = current_direction.linear_interpolate(target_direction, rotation_speed * delta).angle()

timothybrentwood | 2021-05-11 02:23

I don’t know if it will be a good solution because how I have it is:

Every time the player moves the mouse, the character points to where the camera is, then in a Ysort node (which is where the sprite I want with relay is) in the _process function of Ysort I check if they do not have the same angle, yes It is different that I gently fix it

Facu1245 | 2021-05-11 02:46

:bust_in_silhouette: Reply From: magicalogic

Try to interpolate the rotation, you can see how interpolation works here.

:bust_in_silhouette: Reply From: Facu1245

More or less I was able to achieve the effect I wanted using linear_interpolate and an array:


if event is InputEventMouseMotion:


var previous_direction: Array = []

func _process(delta):

 if previous_direction.size() > 2:
	var look: Vector2 = previous_direction[0].linear_interpolate(previous_direction[previous_direction.size() -1], delta)

if previous_direction.size() > 2:

This code works, but if the player is still, when the player moves the body looks in any direction, now if I don’t know how to solve it

Facu1245 | 2021-05-12 01:02