Players standing on the edge of the platform can also jump down.

玩家站在平台边缘也可以向下跳跃了。
This commit is contained in:
Cold-Mint 2024-10-10 16:29:54 +08:00
parent eb6be280e0
commit fc1a12acd0
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
3 changed files with 34 additions and 9 deletions

View File

@ -116,4 +116,5 @@ log_generated_item_is_empty,生成的物品{0}是空的吗{1}。,Generated item
log_projectile_generate_magic_is_null,没有装填可提供抛射体的法术。,There is no reload spell that provides projectiles.,射出体を提供するスペルを装填していません。
log_projectile_scene_is_null,抛射体场景为空。,Projectile scene is empty.,射出体は空です。
log_projectile_is_null,抛射体为空。,Projectile scene is empty.,射出シーンは空です。
log_projectile_weapon_range,加载法术范围{0}顺序模式吗{1}上次发射法术时采用的索引{2}。,Load spell range {0} Sequential mode {1} Index used when the spell was last fired {2}.,スペル範囲{0}順序モードですか{1}前回スペルを送信した時のインデックス{2}。
log_projectile_weapon_range,加载法术范围{0}顺序模式吗{1}上次发射法术时采用的索引{2}。,Load spell range {0} Sequential mode {1} Index used when the spell was last fired {2}.,スペル範囲{0}順序モードですか{1}前回スペルを送信した時のインデックス{2}。
log_no_platform_detection_raycast_found,缺少必要的平台检测射线。,Lack of necessary platform detection rays.,放射線を検出するのに必要なプラットフォームが不足しています。
1 id zh en ja
116 log_projectile_generate_magic_is_null 没有装填可提供抛射体的法术。 There is no reload spell that provides projectiles. 射出体を提供するスペルを装填していません。
117 log_projectile_scene_is_null 抛射体场景为空。 Projectile scene is empty. 射出体は空です。
118 log_projectile_is_null 抛射体为空。 Projectile scene is empty. 射出シーンは空です。
119 log_projectile_weapon_range 加载法术范围{0}顺序模式吗{1}上次发射法术时采用的索引{2}。 Load spell range {0} Sequential mode {1} Index used when the spell was last fired {2}. スペル範囲{0}順序モードですか{1}前回スペルを送信した時のインデックス{2}。
120 log_no_platform_detection_raycast_found 缺少必要的平台检测射线。 Lack of necessary platform detection rays. 放射線を検出するのに必要なプラットフォームが不足しています。

View File

@ -22,19 +22,19 @@ animations = [{
"speed": 5.0
}]
[node name="Player" type="CharacterBody2D"]
[node name="Player" type="CharacterBody2D" node_paths=PackedStringArray("_platformDetectionRayCast2DList")]
light_mask = 2
collision_layer = 4
collision_mask = 162
platform_floor_layers = 4294967042
platform_wall_layers = 128
script = ExtResource("1_1dlls")
_platformDetectionRayCast2DList = [NodePath("PlatformDetectionRayCast1"), NodePath("PlatformDetectionRayCast2"), NodePath("PlatformDetectionRayCast3")]
MaxHp = 32
CampId = "Default"
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CapsuleShape2D_bb8wt")
debug_color = Color(0.886275, 0, 0.803922, 0.419608)
[node name="Area2DPickingArea" type="Area2D" parent="."]
collision_layer = 0
@ -50,7 +50,15 @@ sprite_frames = SubResource("SpriteFrames_qumby")
width = 5.0
default_color = Color(0.858824, 0.65098, 0.682353, 1)
[node name="PlatformDetectionRayCast" type="RayCast2D" parent="."]
[node name="PlatformDetectionRayCast1" type="RayCast2D" parent="."]
collision_mask = 32
[node name="PlatformDetectionRayCast2" type="RayCast2D" parent="."]
position = Vector2(20, 0)
collision_mask = 32
[node name="PlatformDetectionRayCast3" type="RayCast2D" parent="."]
position = Vector2(-20, 0)
collision_mask = 32
[node name="ItemMarker2D" type="Marker2D" parent="."]

View File

@ -23,7 +23,7 @@ public partial class Player : CharacterTemplate
private Line2D? _parabola;
//用于检测玩家是否站在平台上的射线
private RayCast2D? _platformDetectionRayCast2D;
[Export] private RayCast2D[]? _platformDetectionRayCast2DList;
//抛出物品的飞行速度
private float _throwingVelocity = Config.CellSize * 13;
@ -41,11 +41,15 @@ public partial class Player : CharacterTemplate
public override void _Ready()
{
base._Ready();
if (_platformDetectionRayCast2DList == null || _platformDetectionRayCast2DList.Length == 0)
{
LogCat.LogError("no_platform_detection_raycast_found");
return;
}
CharacterName = TranslationServerUtils.Translate("default_player_name");
LogCat.LogWithFormat("player_spawn_debug", LogCat.LogLabel.Default, LogCat.UploadFormat, ReadOnlyCharacterName,
GlobalPosition);
_parabola = GetNode<Line2D>("Parabola");
_platformDetectionRayCast2D = GetNode<RayCast2D>("PlatformDetectionRayCast");
var healthBarUi = GameSceneDepend.HealthBarUi;
if (healthBarUi != null)
{
@ -107,15 +111,27 @@ public partial class Player : CharacterTemplate
{
}
protected override void HookPhysicsProcess(ref Vector2 velocity, double delta)
/// <summary>
/// <para>UpdateCollidingWithPlatform</para>
/// <para>更新与平台发生碰撞的状态</para>
/// </summary>
private void UpdateCollidingWithPlatform()
{
//When the collision state between the platform detection ray and the platform changes
//在平台检测射线与平台碰撞状态改变时
if (_platformDetectionRayCast2D != null && _platformDetectionRayCast2D.IsColliding() != _collidingWithPlatform)
if (_platformDetectionRayCast2DList is not { Length: > 0 }) return;
foreach (var rayCast2D in _platformDetectionRayCast2DList)
{
_collidingWithPlatform = _platformDetectionRayCast2D.IsColliding();
if (!rayCast2D.IsColliding()) continue;
_collidingWithPlatform = true;
return;
}
_collidingWithPlatform = false;
}
protected override void HookPhysicsProcess(ref Vector2 velocity, double delta)
{
UpdateCollidingWithPlatform();
//If the character is on the ground, give an upward velocity when the jump button is pressed
//如果角色正在地面上,按下跳跃键时,给予一个向上的速度
if (Input.IsActionJustPressed("ui_up") && IsOnFloor())