@GarromOrcShaman said:
It rotates but not right, Nodes start spinning around target like planets around star.
Yeah, I tested the code as well and it does not work... I guess things have changed (or, more likely, I forgot) :lol:
I'm able to get correct direction with code below.I just need to know how to smoothly interpolate between actual rotation and target rotation.
I tried your code and made a small change to smoothly rotate. It seems to work nicely, though I'm not sure if using lerp
will reduce performance or not...
extends Sprite
export (NodePath) var path_to_target;
var target;
const ROTATION_SPEED = 20;
func _ready():
target = get_node(path_to_target);
func _process(delta):
var vector_towards_target = target.global_position - self.global_position;
var angle = (atan2(vector_towards_target.y, vector_towards_target.x));
rotation = lerp(rotation, angle, delta * ROTATION_SPEED);