0 votes
    var player_pos = player.global_transform
var t = top_tank.global_transform.looking_at(Vector3(player_pos.origin.x, 0, player_pos.origin.z), Vector3.UP).affine_inverse()
var rot = Quat(top_tank.global_transform.basis.orthonormalized()).slerp(Quat(t.basis), rotation_speed * delta)
    top_tank.global_transform = Transform(Basis(rot), top_tank.global_transform.origin)

The issue here is "tank" is looking at the opposite of the player. So the barrel is looking away from the player at all times. The model of the tank is looking in the negative Z direction but I don't want to edit the model to make this work, considering that the player also uses it. It will mess the player up so I would rather find a way to calculate the opposite direction, but I just can't see a fix. Might be overseeing something so simple here.

Godot version Godot 3.3.3.stable.mono
in Engine by (26 points)

1 Answer

0 votes

Might not be the best solution, but all I did was add the following code after 'var t':

t.basis.z = t.basis.z * -1
t.basis.x = t.basis.x * -1

Pretty simple. Just inverting the x and z basis. I was trying to go about it the more complicated way of trying to offset it in another way but printing the basis made me realize I needed another approach.

by (26 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 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 webmaster@godotengine.org with your username.