- Edited
Godot Version 4.2
I have a 3D turret that can only rotate in 8 directions (eg. every 45degrees). How can I get it to rotate to the direction corresponding with the βzoneβ that the player is in? Also, how to make turret smoothly rotate between those angles as well.
func _process(delta):
var node3d_rotation = node3D.global_rotation_degrees.y
var rotate_target = 0
node3D.look_at(player.global_transform.origin,Vector3.UP)
if (node3d_rotation < 25 and node3d_rotation > -25):
rotate_target = 0
elif node3d_rotation > 25 and node3d_rotation < 75 :
rotate_target = PI/4
elif node3d_rotation > 75 and node3d_rotation < 112 :
rotate_target = PI/2
etc...
turret.rotation.y = rotate_toward(turret.rotation.y, rotate_target, 2 * delta)
Above is my wonky hard coded solution, but I'd like a better way to code this (eg, not depends on global rotation, since I will place/rotate the turret node around the stage). Thanks
Some background on this question
https://forum.godotengine.org/t/gun-turret-aim-at-player-with-only-8-rotating-directions/69080/10