- Edited
Hi all, I have what I thought would be easy to find but is proving to be difficult to find the answer to. I have my player that is being moved from place to place using a tween. Works just fine! But now I need to rotate the player to face the direction they are being moved to, and this is proving a little more difficult. Looking for some help!
var tween = get_tree().create_tween().bind_node(self).set_trans(Tween.TRANS_LINEAR)
tween.tween_property(self, "position", pos, ENUMS.walk_speed)
var target_rotation
tween.tween_property(self, "rotation:y", target_rotation, 0.5)
I need to figure out how to determine the "target_rotation" variable. I have tried a few different methods, but nothing seems to work properly. Anyone know how I figure out this one?
Edit:
My current build has this for its code:
var dir = (target - self.global_position).normalized()
var ang = atan2(dir.x, dir.z) + PI
tween.tween_property(self, "rotation:y", ang, 1.0)
Which works fairly well, except the rotation is always the same direction rather than taking the rotation that is shortest. That'll be the next problem to solve if anyone has any tips!