Modified the knockback algorithm.
修改击退算法。
This commit is contained in:
parent
d3f2076b11
commit
4f16214885
|
@ -14,10 +14,10 @@ _durability = 1.0
|
||||||
_maxDamage = 10
|
_maxDamage = 10
|
||||||
_minDamage = 1
|
_minDamage = 1
|
||||||
_damageType = 2
|
_damageType = 2
|
||||||
_knockBackForce = Vector2(0, 1)
|
|
||||||
Speed = 500.0
|
Speed = 500.0
|
||||||
_enableTracking = true
|
_enableTracking = true
|
||||||
_targetDiesDestroyProjectile = true
|
_targetDiesDestroyProjectile = true
|
||||||
|
_repelStrength = 2.5
|
||||||
|
|
||||||
[node name="CurseOfTheUndead" type="Sprite2D" parent="."]
|
[node name="CurseOfTheUndead" type="Sprite2D" parent="."]
|
||||||
texture = ExtResource("1_k8el6")
|
texture = ExtResource("1_k8el6")
|
||||||
|
|
|
@ -16,8 +16,8 @@ size = Vector2(20, 46)
|
||||||
size = Vector2(53, 24)
|
size = Vector2(53, 24)
|
||||||
|
|
||||||
[sub_resource type="NavigationPolygon" id="NavigationPolygon_rh1gx"]
|
[sub_resource type="NavigationPolygon" id="NavigationPolygon_rh1gx"]
|
||||||
vertices = PackedVector2Array(501, 150, 9, 151, 11, 107, 43, 107, 170, 41, 169, 11, 217, 11, 219, 42, 42, 44, 470, 107, 499, 106, 469, 43)
|
vertices = PackedVector2Array(499.469, 106.328, 501.523, 150.039, 9.3125, 151.953, 470.156, 107.352, 10.7031, 107, 43.1562, 107, 170.328, 40.6797, 169.344, 11, 216.617, 11, 218.617, 41.9297, 469.148, 43.9219, 42.1484, 44.6875)
|
||||||
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3), PackedInt32Array(4, 5, 6, 7), PackedInt32Array(0, 3, 8, 4, 7, 9), PackedInt32Array(9, 10, 0), PackedInt32Array(9, 7, 11)])
|
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3), PackedInt32Array(3, 2, 4, 5), PackedInt32Array(6, 7, 8, 9), PackedInt32Array(10, 3, 5, 9), PackedInt32Array(6, 9, 5, 11)])
|
||||||
outlines = Array[PackedVector2Array]([PackedVector2Array(479, 34, 228, 32, 226, 1, 159, 1, 160, 31, 32, 35, 33, 97, 1, 97, -1, 162, 512, 160, 509, 96, 480, 97)])
|
outlines = Array[PackedVector2Array]([PackedVector2Array(479, 34, 228, 32, 226, 1, 159, 1, 160, 31, 32, 35, 33, 97, 1, 97, -1, 162, 512, 160, 509, 96, 480, 97)])
|
||||||
source_geometry_group_name = &"navigation_polygon_source_group"
|
source_geometry_group_name = &"navigation_polygon_source_group"
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,8 @@ size = Vector2(46, 20)
|
||||||
size = Vector2(20, 54)
|
size = Vector2(20, 54)
|
||||||
|
|
||||||
[sub_resource type="NavigationPolygon" id="NavigationPolygon_db40i"]
|
[sub_resource type="NavigationPolygon" id="NavigationPolygon_db40i"]
|
||||||
vertices = PackedVector2Array(499, 108, 501, 150, 246, 149, 471, 108, 12, 149, 11, 107, 41, 107, 203, 149, 245, 180, 203, 178, 43, 43, 470, 44)
|
vertices = PackedVector2Array(499.461, 108, 501.5, 150.906, 246.312, 148.922, 471.156, 108, 245.312, 180.508, 203, 178.469, 203, 149, 11.8438, 149, 11.1562, 107.656, 40.5625, 106.688, 43.5391, 43.0391, 470.148, 44.9531)
|
||||||
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3), PackedInt32Array(4, 5, 6, 7), PackedInt32Array(2, 8, 9, 7), PackedInt32Array(10, 11, 3, 2, 7, 6)])
|
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3), PackedInt32Array(2, 4, 5, 6), PackedInt32Array(7, 8, 9, 6), PackedInt32Array(10, 11, 3, 2, 6, 9)])
|
||||||
outlines = Array[PackedVector2Array]([PackedVector2Array(34, 33, 31, 97, 1, 98, 2, 159, 193, 159, 193, 188, 255, 191, 256, 159, 512, 161, 509, 98, 481, 98, 480, 35)])
|
outlines = Array[PackedVector2Array]([PackedVector2Array(34, 33, 31, 97, 1, 98, 2, 159, 193, 159, 193, 188, 255, 191, 256, 159, 512, 161, 509, 98, 481, 98, 480, 35)])
|
||||||
source_geometry_group_name = &"navigation_polygon_source_group"
|
source_geometry_group_name = &"navigation_polygon_source_group"
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,9 @@ size = Vector2(450, 191)
|
||||||
size = Vector2(18, 57.75)
|
size = Vector2(18, 57.75)
|
||||||
|
|
||||||
[sub_resource type="NavigationPolygon" id="NavigationPolygon_064c7"]
|
[sub_resource type="NavigationPolygon" id="NavigationPolygon_064c7"]
|
||||||
vertices = PackedVector2Array(468, 174, 500, 174, 499, 214, 41, 214, 45, 45, 468, 45)
|
vertices = PackedVector2Array(467.773, 174, 499.828, 174, 499.156, 214.969, 40.9375, 214.023, 40.0469, 41.0625, 470.758, 43.9297)
|
||||||
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3), PackedInt32Array(0, 3, 4, 5)])
|
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3), PackedInt32Array(0, 3, 4, 5)])
|
||||||
outlines = Array[PackedVector2Array]([PackedVector2Array(35, 35, 31, 224, 509, 225, 510, 164, 478, 164, 478, 35)])
|
outlines = Array[PackedVector2Array]([PackedVector2Array(30, 31, 31, 224, 509, 225, 510, 164, 478, 164, 481, 34)])
|
||||||
source_geometry_group_name = &"navigation_polygon_source_group"
|
source_geometry_group_name = &"navigation_polygon_source_group"
|
||||||
|
|
||||||
[node name="InitialRoom" type="Node2D"]
|
[node name="InitialRoom" type="Node2D"]
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
[ext_resource type="TileSet" uid="uid://c4wpp12rr44hi" path="res://tileSets/dungeon.tres" id="1_rn2om"]
|
[ext_resource type="TileSet" uid="uid://c4wpp12rr44hi" path="res://tileSets/dungeon.tres" id="1_rn2om"]
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_kiih8"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_kiih8"]
|
||||||
size = Vector2(669, 442)
|
size = Vector2(664, 435)
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_o85u0"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_o85u0"]
|
||||||
size = Vector2(20, 48)
|
size = Vector2(20, 48)
|
||||||
|
@ -15,7 +15,7 @@ size = Vector2(22, 46)
|
||||||
size = Vector2(11.875, 51)
|
size = Vector2(11.875, 51)
|
||||||
|
|
||||||
[sub_resource type="NavigationPolygon" id="NavigationPolygon_1qloc"]
|
[sub_resource type="NavigationPolygon" id="NavigationPolygon_1qloc"]
|
||||||
vertices = PackedVector2Array(696, 425, 720, 425, 722, 467, 12, 470, 10, 426, 46, 424, 691, 84, 45, 48, 721, 44, 723, 80)
|
vertices = PackedVector2Array(696.148, 425, 719.617, 425, 722.328, 467.047, 12.5391, 470.938, 10.4531, 426.43, 46.0312, 424.461, 690.859, 84.1562, 45.0234, 48.9219, 721.523, 44.0625, 723.5, 80.1875)
|
||||||
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3, 4), PackedInt32Array(0, 4, 5), PackedInt32Array(6, 0, 5, 7), PackedInt32Array(6, 7, 8, 9)])
|
polygons = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3, 4), PackedInt32Array(0, 4, 5), PackedInt32Array(6, 0, 5, 7), PackedInt32Array(6, 7, 8, 9)])
|
||||||
outlines = Array[PackedVector2Array]([PackedVector2Array(35, 39, 36, 415, 0, 417, 3, 481, 733, 477, 729, 415, 706, 415, 701, 93, 734, 89, 731, 34)])
|
outlines = Array[PackedVector2Array]([PackedVector2Array(35, 39, 36, 415, 0, 417, 3, 481, 733, 477, 729, 415, 706, 415, 701, 93, 734, 89, 731, 34)])
|
||||||
source_geometry_group_name = &"navigation_polygon_source_group"
|
source_geometry_group_name = &"navigation_polygon_source_group"
|
||||||
|
@ -26,7 +26,7 @@ source_geometry_group_name = &"navigation_polygon_source_group"
|
||||||
collision_mask = 0
|
collision_mask = 0
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="RoomArea"]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="RoomArea"]
|
||||||
position = Vector2(367.5, 256)
|
position = Vector2(370, 259.5)
|
||||||
shape = SubResource("RectangleShape2D_kiih8")
|
shape = SubResource("RectangleShape2D_kiih8")
|
||||||
|
|
||||||
[node name="RoomSlotList" type="Node2D" parent="."]
|
[node name="RoomSlotList" type="Node2D" parent="."]
|
||||||
|
|
|
@ -2,7 +2,6 @@ using System;
|
||||||
using ColdMint.scripts.debug;
|
using ColdMint.scripts.debug;
|
||||||
using ColdMint.scripts.pickable;
|
using ColdMint.scripts.pickable;
|
||||||
using ColdMint.scripts.utils;
|
using ColdMint.scripts.utils;
|
||||||
using ColdMint.scripts.weapon;
|
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace ColdMint.scripts.inventory;
|
namespace ColdMint.scripts.inventory;
|
||||||
|
|
|
@ -38,16 +38,6 @@ public partial class Projectile : CharacterBody2D
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private DateTime? _destructionTime;
|
private DateTime? _destructionTime;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// <para>knockBack</para>
|
|
||||||
/// <para>击退</para>
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
///<para>How much force does it have when hitting the character? Unit: Number of cells,The X direction of the force is inferred automatically.</para>
|
|
||||||
///<para>当击中角色时带有多大的力?单位:格数,力的X方向是自动推断的。</para>
|
|
||||||
/// </remarks>
|
|
||||||
[Export] private Vector2 _knockBackForce;
|
|
||||||
|
|
||||||
[Export] public float Speed;
|
[Export] public float Speed;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -88,6 +78,16 @@ public partial class Projectile : CharacterBody2D
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private RayCast2D? _wallRayCast;
|
private RayCast2D? _wallRayCast;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>Repel strength</para>
|
||||||
|
/// <para>击退强度</para>
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
///<para>Must be greater than 0, the unit is in format.</para>
|
||||||
|
///<para>必须大于0,单位为格式。</para>
|
||||||
|
/// </remarks>
|
||||||
|
[Export] private float _repelStrength;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>The master of the weapon</para>
|
/// <para>The master of the weapon</para>
|
||||||
/// <para>武器的主人</para>
|
/// <para>武器的主人</para>
|
||||||
|
@ -117,6 +117,7 @@ public partial class Projectile : CharacterBody2D
|
||||||
SetCollisionMaskValue(Config.LayerNumber.Floor, !_ignoreWall);
|
SetCollisionMaskValue(Config.LayerNumber.Floor, !_ignoreWall);
|
||||||
SetCollisionMaskValue(Config.LayerNumber.Player, true);
|
SetCollisionMaskValue(Config.LayerNumber.Player, true);
|
||||||
SetCollisionMaskValue(Config.LayerNumber.Mob, true);
|
SetCollisionMaskValue(Config.LayerNumber.Mob, true);
|
||||||
|
SetCollisionMaskValue(Config.LayerNumber.PickAbleItem, true);
|
||||||
//Platform collision layer is not allowed to collide
|
//Platform collision layer is not allowed to collide
|
||||||
//平台碰撞层不可碰撞
|
//平台碰撞层不可碰撞
|
||||||
SetCollisionMaskValue(Config.LayerNumber.Platform, false);
|
SetCollisionMaskValue(Config.LayerNumber.Platform, false);
|
||||||
|
@ -239,42 +240,24 @@ public partial class Projectile : CharacterBody2D
|
||||||
InvokeDecorators(decorator => { decorator.OnKillCharacter(owner, characterTemplate); });
|
InvokeDecorators(decorator => { decorator.OnKillCharacter(owner, characterTemplate); });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_knockBackForce != Vector2.Zero)
|
if (_repelStrength > 0)
|
||||||
{
|
{
|
||||||
//If we set the attack force, then apply the force to the object
|
//If we set the attack force, then apply the force to the object
|
||||||
//如果我们设置了攻退力,那么将力应用到对象上
|
//如果我们设置了攻退力,那么将力应用到对象上
|
||||||
var force = new Vector2();
|
var normalized = Velocity.Normalized();
|
||||||
var forceX = Math.Abs(_knockBackForce.X);
|
characterTemplate.AddForce(new Vector2(normalized.X * _repelStrength * Config.CellSize,
|
||||||
if (Velocity.X < 0)
|
normalized.Y * _repelStrength * Config.CellSize));
|
||||||
{
|
|
||||||
//Beat back to port
|
|
||||||
//向左击退
|
|
||||||
forceX = -forceX;
|
|
||||||
}
|
|
||||||
|
|
||||||
force.X = forceX * Config.CellSize;
|
|
||||||
force.Y = _knockBackForce.Y * Config.CellSize;
|
|
||||||
characterTemplate.AddForce(force);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (target is PickAbleTemplate pickAbleTemplate)
|
else if (target is PickAbleTemplate pickAbleTemplate)
|
||||||
{
|
{
|
||||||
if (_knockBackForce != Vector2.Zero)
|
if (_repelStrength > 0)
|
||||||
{
|
{
|
||||||
//If we set the attack force, then apply the force to the object
|
//If we set the attack force, then apply the force to the object
|
||||||
//如果我们设置了攻退力,那么将力应用到对象上
|
//如果我们设置了攻退力,那么将力应用到对象上
|
||||||
var force = new Vector2();
|
var normalized = Velocity.Normalized();
|
||||||
var forceX = Math.Abs(_knockBackForce.X);
|
pickAbleTemplate.ApplyImpulse(new Vector2(normalized.X * _repelStrength * Config.CellSize,
|
||||||
if (Velocity.X < 0)
|
normalized.Y * _repelStrength * Config.CellSize));
|
||||||
{
|
|
||||||
//Beat back to port
|
|
||||||
//向左击退
|
|
||||||
forceX = -forceX;
|
|
||||||
}
|
|
||||||
|
|
||||||
force.X = forceX * Config.CellSize;
|
|
||||||
force.Y = _knockBackForce.Y * Config.CellSize;
|
|
||||||
pickAbleTemplate.ApplyImpulse(force);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user