Hi,
im trying to develop a rts game (just started with using godot) and am trying to make it look like the units use the old 8 directional movment from the 2d rts games like command and conquer. Therfore I want to make the unit face in the y-direction closest to the actual movement direction, while turning only in 45° increments. (-180, -135, -90, -45, 0, 45 , 90, 135 , 180) I can get the nessesary angles based on the global transform and make it into 8 directions via stepify. But if I try to apply the y-rotation based on that angle it doesn't work and just faces some directions that don't match where they are supposed to face.
I assume my error is somewhere in the way I aquire the angle, as the rotation value is completely messed up when I add the line self.rotat_y(rot)
I got the formula for the rotation from a post, where someone also wanted to get the rotation of his object, so I'm not really sure how it works.
Thanks to those reading and trying to help
move_and_slide_with_snap(move_vec.normalized() * move_speed, Vector3.DOWN, Vector3.UP, true)
var direction = global_transform.origin - move_vec.normalized()
look_at(direction, Vector3.UP)
var rot = stepify(Vector2(global_transform.basis.z.x,global_transform.basis.z.z).angle_to(Vector2(0,1)), PI/4)
rot = rad2deg(rot)
self.rotate_y(rot)