Attention | Topic was automatically imported from the old Question2Answer platform. | |
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.