look_at without rotating the sprite? or maybe an alternative method

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

This code is for turrets to aim at the enemy

func _process(delta):
var dist = global_position.distance_to(enemy.global_position)
look_at(enemy.global_position + enemy.enemy_vol * (dist/10))

but I don’t want the turrets’ sprite to rotate with it.

:bust_in_silhouette: Reply From: love_this_name

You can get the unit vector that points towards a target like this:

var direction = ( target.get_pos() - self.get_pos() ).normalized()

credit to @YeOldeDM from this post

Thanks, it works nicely!
Can direction_to() also be used for this? If so, how does it look like? I got “nonexistent function” when I tried it before which is likely caused by wrong syntax.

Undorobo | 2022-10-16 09:57