Tank turrent rotation offseted

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

Hello guys!

I’m creating a tank game and I’m having trouble rotating the enemy cannon towards the player. The direction has a 90 degree offset and I don’t know what I’m doing wrong. Can you help me?

The code that i’m using:
var target_dir = (target.global_position - global_position).normalized() print(target_dir) var current_dir = Vector2(1,0).rotated($turrent.global_rotation) $turrent.global_rotation = current_dir.linear_interpolate(target_dir, turrent_speed * delta).angle()

I’ve already tried to subtract 90 degrees but it doesn’t work out.

Here’s a gif to show you what’s happening:

:bust_in_silhouette: Reply From: njamster

Your code works fine for me. Educated guess: your “turrent” (you’re aware it’s called “turret”, aren’t you?) is not facing to the right when it’s rotation is set to 0.