Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / activity / role / Role_Animation.cs
@小李xl 小李xl on 3 Dec 2023 2 KB 修复武器中心点问题
  1.  
  2. using System;
  3. using Godot;
  4. using Vector2 = Godot.Vector2;
  5.  
  6. public partial class Role
  7. {
  8. /// <summary>
  9. /// 播放近战攻击动画
  10. /// </summary>
  11. public virtual void PlayAnimation_MeleeAttack(Action finish)
  12. {
  13. var r = MountPoint.RotationDegrees;
  14. //var gp = MountPoint.GlobalPosition;
  15. var p1 = MountPoint.Position;
  16. var p2 = p1 + new Vector2(6, 0).Rotated(Mathf.DegToRad(r - MeleeAttackAngle / 2f));
  17. var p3 = p1 + new Vector2(6, 0).Rotated(Mathf.DegToRad(r + MeleeAttackAngle / 2f));
  18. var tween = CreateTween();
  19. tween.SetParallel();
  20. tween.TweenProperty(MountPoint, "rotation_degrees", r - MeleeAttackAngle / 2f, 0.1);
  21. tween.TweenProperty(MountPoint, "position", p2, 0.1);
  22. tween.TweenProperty(MountPoint, "position", p2, 0.1);
  23. tween.Chain();
  24.  
  25. tween.TweenCallback(Callable.From(() =>
  26. {
  27. MountPoint.RotationDegrees = r + MeleeAttackAngle / 2f;
  28. MountPoint.Position = p3;
  29. //重新计算武器阴影位置
  30. var activeItem = WeaponPack.ActiveItem;
  31. activeItem.CalcShadowTransform();
  32. //创建屏幕抖动
  33. if (Face == FaceDirection.Right)
  34. {
  35. //GameCamera.Main.DirectionalShake(Vector2.FromAngle(Mathf.DegToRad(r - 90)) * 5);
  36. GameCamera.Main.DirectionalShake(Vector2.FromAngle(Mathf.DegToRad(r - 180)) * 6);
  37. }
  38. else
  39. {
  40. //GameCamera.Main.DirectionalShake(Vector2.FromAngle(Mathf.DegToRad(270 - r)) * 5);
  41. GameCamera.Main.DirectionalShake(Vector2.FromAngle(Mathf.DegToRad(-r)) * 6);
  42. }
  43. //播放特效
  44. var effect = ObjectManager.GetPoolItem<IEffect>(ResourcePath.prefab_effect_weapon_MeleeAttack1_tscn);
  45. var sprite = (Node2D)effect;
  46. var localFirePosition = activeItem.GetLocalFirePosition() - activeItem.Position;
  47. localFirePosition *= 0.9f;
  48. sprite.Position = p1 + localFirePosition.Rotated(Mathf.DegToRad(r));
  49. sprite.RotationDegrees = r;
  50. AddChild(sprite);
  51. effect.PlayEffect();
  52.  
  53. //启用近战碰撞区域
  54. MeleeAttackCollision.Disabled = false;
  55. }));
  56. tween.Chain();
  57. tween.TweenInterval(0.1f);
  58. tween.Chain();
  59.  
  60. tween.TweenCallback(Callable.From(() =>
  61. {
  62. //关闭近战碰撞区域
  63. MeleeAttackCollision.Disabled = true;
  64. }));
  65. tween.TweenProperty(MountPoint, "rotation_degrees", r, 0.2);
  66. tween.TweenProperty(MountPoint, "position", p1, 0.2);
  67. tween.Chain();
  68. tween.TweenCallback(Callable.From(() =>
  69. {
  70. finish();
  71. }));
  72. tween.Play();
  73. }
  74. }