Advertisement
Siandfrance

Calculate a vertical and horisontal angles

Jul 16th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. #calculate the horizontal angle
  2. var horizontal_rotation: float = rad2deg(
  3.     Vector2(bot_pos.x, bot_pos.z).angle_to_point(
  4.     Vector2(player_pos.x, player_pos.z))
  5.     + bot_rotation.y) - 90
  6. #constrain the angle between -180 and 180 to be easyer to use
  7. if horizontal_rotation < -180:
  8.     horizontal_rotation += 360
  9. elif horizontal_rotation > 180:
  10.     horizontal_rotation -= 360
  11.  
  12. #calculate the vertical angle
  13. var vertical_rotation: float = rad2deg(
  14.     Vector2(bot_pos.y, bot_pos.z).angle_to_point(
  15.     Vector2(player_pos.y, player_pos.z))
  16.      + bot_rotation.x) - 90
  17. #and constain it
  18. if vertical_rotation < -180:
  19.     vertical_rotation += 360
  20. elif vertical_rotation > 180:
  21.     vertical_rotation -= 360
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement