Godot Quat looking in wrong direciton

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By profjle
    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.

:bust_in_silhouette: Reply From: profjle

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.