Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / role / MountRotation.cs
@小李xl 小李xl on 5 Nov 2022 1 KB 添加受击效果
  1.  
  2. using Godot;
  3.  
  4. /// <summary>
  5. /// 用于限定 Position2D 节点的旋转角度
  6. /// </summary>
  7. public class MountRotation : Position2D
  8. {
  9. /// <summary>
  10. /// 吸附角度
  11. /// </summary>
  12. private int _adsorption = 6;
  13. /// <summary>
  14. /// 所在的角色
  15. /// </summary>
  16. public Role Master { get; set; }
  17.  
  18. /// <summary>
  19. /// 当前节点真实的旋转角度
  20. /// </summary>
  21. public float RealAngle { get; private set; }
  22.  
  23. /// <summary>
  24. /// 设置看向的目标点
  25. /// </summary>
  26. /// <param name="target"></param>
  27. public void SetLookAt(Vector2 target)
  28. {
  29. var myPos = GlobalPosition;
  30. var angle = Mathf.Rad2Deg((target - myPos).Angle());
  31.  
  32. if (Master.Face == FaceDirection.Left)
  33. {
  34. if (angle < 0 && angle > -80)
  35. {
  36. angle = -80;
  37. }
  38. else if (angle >= 0 && angle < 80)
  39. {
  40. angle = 80;
  41. }
  42. }
  43. else
  44. {
  45. angle = Mathf.Clamp(angle, -100, 100);
  46. }
  47.  
  48. RealAngle = angle;
  49.  
  50. if (Master.GlobalPosition.x >= target.x)
  51. {
  52. angle = -angle;
  53. }
  54.  
  55. GlobalRotationDegrees = AdsorptionAngle(angle);
  56. }
  57.  
  58. private float AdsorptionAngle(float angle)
  59. {
  60. return ((int)angle / _adsorption) * _adsorption;
  61. }
  62. }