0 votes

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.

Godot version 3.5
in Engine by (19 points)

1 Answer

+1 vote
Best answer

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

by (146 points)
selected by

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.

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 Frequently asked questions and 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 [email protected] with your username.