Problems with pointing FPS gun towards enemies

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

I’m trying to make the gun look at a nearby enemy, but instead, it just looks at a random general direction, and doesn’t appear to be focusing on anything.

Here’s the code:

func _on_Shoot_Area_body_entered(body):
if body.is_in_group("AI"):
target = body.global_transform.origin
target.x -= 179

Here’s what it’s doing:

What do I do?