Improved weapon recoil effect.

改进武器的后座力效果。
This commit is contained in:
Cold-Mint 2024-09-01 22:25:20 +08:00
parent 1ef0f08e2f
commit c1a3bfa266
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
2 changed files with 9 additions and 15 deletions

View File

@ -21,6 +21,7 @@ OffsetAngle = 0.087
ProjectileScenes = [ExtResource("2_mwli5")] ProjectileScenes = [ExtResource("2_mwli5")]
Sequentially = true Sequentially = true
FiringIntervalAsMillisecond = 300 FiringIntervalAsMillisecond = 300
_recoilStrength = 5
UniqueIcon = ExtResource("3_31iau") UniqueIcon = ExtResource("3_31iau")
[node name="DamageArea2D" type="Area2D" parent="."] [node name="DamageArea2D" type="Area2D" parent="."]

View File

@ -38,8 +38,11 @@ public abstract partial class WeaponTemplate : PickAbleTemplate
/// <para>开火间隔</para> /// <para>开火间隔</para>
/// </summary> /// </summary>
private TimeSpan _firingInterval; private TimeSpan _firingInterval;
private long _firingIntervalAsMillisecond = 100; private long _firingIntervalAsMillisecond = 100;
[Export] protected long FiringIntervalAsMillisecond
[Export]
protected long FiringIntervalAsMillisecond
{ {
get => _firingIntervalAsMillisecond; get => _firingIntervalAsMillisecond;
set set
@ -58,7 +61,7 @@ public abstract partial class WeaponTemplate : PickAbleTemplate
///<para>When the weapon is fired, how much recoil is applied to the user, in units: the number of cells, and the X direction of the force is automatically inferred.</para> ///<para>When the weapon is fired, how much recoil is applied to the user, in units: the number of cells, and the X direction of the force is automatically inferred.</para>
///<para>武器开火要对使用者施加多大的后坐力单位格数力的X方向是自动推断的。</para> ///<para>武器开火要对使用者施加多大的后坐力单位格数力的X方向是自动推断的。</para>
/// </remarks> /// </remarks>
[Export] private Vector2 _recoil; [Export] private long _recoilStrength;
/// <summary> /// <summary>
/// <para>Discharge of the weapon</para> /// <para>Discharge of the weapon</para>
@ -88,19 +91,9 @@ public abstract partial class WeaponTemplate : PickAbleTemplate
{ {
//We check the recoil of the weapon before each firing. //We check the recoil of the weapon before each firing.
//我们在每次开火之前,检查武器的后坐力。 //我们在每次开火之前,检查武器的后坐力。
if (_recoil != Vector2.Zero) if (_recoilStrength != 0)
{ {
var force = new Vector2(); var force = -characterTemplate.GlobalPosition.DirectionTo(enemyGlobalPosition) * _recoilStrength * Config.CellSize;
var forceX = Math.Abs(_recoil.X);
if (Math.Abs(RotationDegrees) < 90)
{
//The weapon goes to the right, and we apply a recoil to the left
//武器朝向右边我们向左施加后坐力
forceX = -forceX;
}
force.X = forceX * Config.CellSize;
force.Y = _recoil.Y * Config.CellSize;
characterTemplate.AddForce(force); characterTemplate.AddForce(force);
} }
} }