I need to add delay to a sprite of when the parent node rotates, how do I do it ???
How to add delay to a node when its parent rotates
In that case you may want to keep them as separate objects and do the animation yourself. You can try making a Position2D inside the parent where you want the Sprite to go. Then on the Sprite, do some logic in _process to follow the position/rotation, for example with linear_interpolate.
@cybereality said: In that case you may want to keep them as separate objects and do the animation yourself. You can try making a Position2D inside the parent where you want the Sprite to go. Then on the Sprite, do some logic in _process to follow the position/rotation, for example with linear_interpolate.
yes, but in this case the sprite yes or yes has to be inside that node.
Actually it is a kinematicbody2D that is always following the mouse pointer, then it has a Ysort that inside it is the sprite that I want with delay, and it is the same Ysort that checks if the rotation is the same, and if it does not fix it smoothly
This may be sort of a hack, but you can add a script on the child node to do the reverse of the parent rotation (so it will stay in place) and then have a Position2D that is not rotated (same level as the one you want to rotate) and then do the linear interpolate from there. That might work, not sure though.
- Edited
More or less I was able to achieve the effect I wanted using linear_interpolate and an array:
Dad
if event is InputEventMouseMotion:
Body_Sprites.previous_direction.append(get_global_mouse_position())
look_at(get_global_mouse_position())
Child
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)
Body.look_at(look.normalized())
previous_direction.erase(previous_direction[0])
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