From fc1a12acd0edc913b18235bf5ee928ef71936d65 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Thu, 10 Oct 2024 16:29:54 +0800 Subject: [PATCH] =?UTF-8?q?Players=20standing=20on=20the=20edge=20of=20the?= =?UTF-8?q?=20platform=20can=20also=20jump=20down.=20=E7=8E=A9=E5=AE=B6?= =?UTF-8?q?=E7=AB=99=E5=9C=A8=E5=B9=B3=E5=8F=B0=E8=BE=B9=E7=BC=98=E4=B9=9F?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E5=90=91=E4=B8=8B=E8=B7=B3=E8=B7=83=E4=BA=86?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locals/Log.csv | 3 ++- prefab/entitys/Character.tscn | 14 +++++++++++--- scripts/character/Player.cs | 26 +++++++++++++++++++++----- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/locals/Log.csv b/locals/Log.csv index 2816f9b..39eaa49 100644 --- a/locals/Log.csv +++ b/locals/Log.csv @@ -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}。 \ No newline at end of file +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.,放射線を検出するのに必要なプラットフォームが不足しています。 \ No newline at end of file diff --git a/prefab/entitys/Character.tscn b/prefab/entitys/Character.tscn index 0ab5716..f18d714 100644 --- a/prefab/entitys/Character.tscn +++ b/prefab/entitys/Character.tscn @@ -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="."] diff --git a/scripts/character/Player.cs b/scripts/character/Player.cs index 3c881d6..9185922 100644 --- a/scripts/character/Player.cs +++ b/scripts/character/Player.cs @@ -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("Parabola"); - _platformDetectionRayCast2D = GetNode("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) + /// + /// UpdateCollidingWithPlatform + /// 更新与平台发生碰撞的状态 + /// + 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())