0 votes

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:
https://gph.is/g/Ev1GQ9z

in Engine by (17 points)

1 Answer

+1 vote

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.

by (10,608 points)
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.