+1 vote

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

Godot version Godot 3.3
in Engine by (25 points)

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()

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

2 Answers

+1 vote

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

by (1,051 points)
0 votes

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())

if previous_direction.size() > 2:
    previous_direction.erase(previous_direction[0])
by (25 points)

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

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 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 webmaster@godotengine.org with your username.