From 0e803bc5f081c86f17c891accc7c0a1ea0a7da23 Mon Sep 17 00:00:00 2001 From: richarjiang Date: Wed, 15 Oct 2025 16:21:10 +0800 Subject: [PATCH] =?UTF-8?q?perf(player):=20=E4=BC=98=E5=8C=96=E7=A7=BB?= =?UTF-8?q?=E5=8A=A8=E6=96=B9=E5=90=91=E8=AE=A1=E7=AE=97=E5=92=8C=E9=81=93?= =?UTF-8?q?=E5=85=B7=E9=A3=9E=E8=A1=8C=E5=8A=A8=E7=94=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 改进移动方向计算逻辑,从移动过程中持续更新改为移动开始前计算一次,提升性能 - 优化道具飞向玩家的动画,使用世界坐标和正确的坐标转换 - 移除触摸开始时自动隐藏弹窗的逻辑 - 调整方向判断算法,优先判断水平方向,更符合梦幻西游风格 --- assets/scenes/main.scene | 725 +++++++++++++++-------------- assets/scripts/PlayerController.ts | 83 ++-- 2 files changed, 421 insertions(+), 387 deletions(-) diff --git a/assets/scenes/main.scene b/assets/scenes/main.scene index a0e36dc..7fed787 100644 --- a/assets/scenes/main.scene +++ b/assets/scenes/main.scene @@ -52,7 +52,7 @@ }, "autoReleaseAssets": false, "_globals": { - "__id__": 243 + "__id__": 244 }, "_id": "58132e64-0171-4c7f-89be-a2984ca7de6b" }, @@ -75,37 +75,37 @@ "__id__": 48 }, { - "__id__": 64 + "__id__": 65 }, { - "__id__": 67 + "__id__": 68 }, { - "__id__": 81 + "__id__": 82 }, { - "__id__": 99 + "__id__": 100 }, { - "__id__": 117 + "__id__": 118 }, { - "__id__": 135 + "__id__": 136 }, { - "__id__": 146 + "__id__": 147 }, { - "__id__": 157 + "__id__": 158 }, { - "__id__": 175 + "__id__": 176 }, { - "__id__": 193 + "__id__": 194 }, { - "__id__": 211 + "__id__": 212 }, { "__id__": 6 @@ -114,19 +114,19 @@ "__id__": 52 }, { - "__id__": 229 + "__id__": 230 }, { - "__id__": 62 + "__id__": 63 }, { - "__id__": 232 + "__id__": 233 }, { - "__id__": 234 + "__id__": 235 }, { - "__id__": 238 + "__id__": 239 }, { "__id__": 56 @@ -135,13 +135,13 @@ "_active": true, "_components": [ { - "__id__": 241 + "__id__": 242 }, { "__id__": 51 }, { - "__id__": 242 + "__id__": 243 } ], "_prefab": null, @@ -1880,7 +1880,7 @@ "__id__": 47 }, "attackAudio": { - "__id__": 62 + "__id__": 63 }, "moveSpeed": 300, "_id": "c1AuAU3IlKnLOzgk9vsBr4" @@ -2056,6 +2056,9 @@ }, { "__id__": 61 + }, + { + "__id__": 62 } ], "_prefab": null, @@ -2271,6 +2274,18 @@ "_atlas": null, "_id": "96QTNs8BhLJL3NFyqluZjm" }, + { + "__type__": "cc.BlockInputEvents", + "_name": "", + "_objFlags": 0, + "__editorExtras__": {}, + "node": { + "__id__": 56 + }, + "_enabled": true, + "__prefab": null, + "_id": "90wOxAZrpFM6Lg8cz0DNPd" + }, { "__type__": "cc.Node", "_name": "Attack", @@ -2283,7 +2298,7 @@ "_active": true, "_components": [ { - "__id__": 63 + "__id__": 64 } ], "_prefab": null, @@ -2322,7 +2337,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 62 + "__id__": 63 }, "_enabled": true, "__prefab": null, @@ -2347,10 +2362,10 @@ "_active": true, "_components": [ { - "__id__": 65 + "__id__": 66 }, { - "__id__": 66 + "__id__": 67 } ], "_prefab": null, @@ -2389,7 +2404,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 64 + "__id__": 65 }, "_enabled": true, "__prefab": null, @@ -2411,7 +2426,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 64 + "__id__": 65 }, "_enabled": true, "__prefab": null, @@ -2433,22 +2448,22 @@ }, "_children": [ { - "__id__": 68 + "__id__": 69 }, { - "__id__": 71 + "__id__": 72 }, { - "__id__": 74 + "__id__": 75 }, { - "__id__": 77 + "__id__": 78 } ], "_active": true, "_components": [ { - "__id__": 80 + "__id__": 81 } ], "_prefab": null, @@ -2487,16 +2502,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 67 + "__id__": 68 }, "_children": [], "_active": true, "_components": [ { - "__id__": 69 + "__id__": 70 }, { - "__id__": 70 + "__id__": 71 } ], "_prefab": null, @@ -2535,7 +2550,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 68 + "__id__": 69 }, "_enabled": true, "__prefab": null, @@ -2557,7 +2572,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 68 + "__id__": 69 }, "_enabled": true, "__prefab": null, @@ -2596,16 +2611,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 67 + "__id__": 68 }, "_children": [], "_active": true, "_components": [ { - "__id__": 72 + "__id__": 73 }, { - "__id__": 73 + "__id__": 74 } ], "_prefab": null, @@ -2644,7 +2659,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 71 + "__id__": 72 }, "_enabled": true, "__prefab": null, @@ -2666,7 +2681,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 71 + "__id__": 72 }, "_enabled": true, "__prefab": null, @@ -2705,16 +2720,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 67 + "__id__": 68 }, "_children": [], "_active": true, "_components": [ { - "__id__": 75 + "__id__": 76 }, { - "__id__": 76 + "__id__": 77 } ], "_prefab": null, @@ -2753,7 +2768,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 74 + "__id__": 75 }, "_enabled": true, "__prefab": null, @@ -2775,7 +2790,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 74 + "__id__": 75 }, "_enabled": true, "__prefab": null, @@ -2814,16 +2829,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 67 + "__id__": 68 }, "_children": [], "_active": true, "_components": [ { - "__id__": 78 + "__id__": 79 }, { - "__id__": 79 + "__id__": 80 } ], "_prefab": null, @@ -2862,7 +2877,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 77 + "__id__": 78 }, "_enabled": true, "__prefab": null, @@ -2884,7 +2899,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 77 + "__id__": 78 }, "_enabled": true, "__prefab": null, @@ -2923,7 +2938,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 67 + "__id__": 68 }, "_enabled": true, "__prefab": null, @@ -2949,28 +2964,28 @@ }, "_children": [ { - "__id__": 82 + "__id__": 83 }, { - "__id__": 85 + "__id__": 86 }, { - "__id__": 89 + "__id__": 90 }, { - "__id__": 92 + "__id__": 93 } ], "_active": true, "_components": [ - { - "__id__": 96 - }, { "__id__": 97 }, { "__id__": 98 + }, + { + "__id__": 99 } ], "_prefab": null, @@ -3009,16 +3024,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 81 + "__id__": 82 }, "_children": [], "_active": true, "_components": [ { - "__id__": 83 + "__id__": 84 }, { - "__id__": 84 + "__id__": 85 } ], "_prefab": null, @@ -3057,7 +3072,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 82 + "__id__": 83 }, "_enabled": true, "__prefab": null, @@ -3079,7 +3094,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 82 + "__id__": 83 }, "_enabled": true, "__prefab": null, @@ -3091,19 +3106,19 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 81 + "__id__": 82 }, "_children": [], "_active": true, "_components": [ - { - "__id__": 86 - }, { "__id__": 87 }, { "__id__": 88 + }, + { + "__id__": 89 } ], "_prefab": null, @@ -3142,7 +3157,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 85 + "__id__": 86 }, "_enabled": true, "__prefab": null, @@ -3164,7 +3179,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 85 + "__id__": 86 }, "_enabled": true, "__prefab": null, @@ -3203,7 +3218,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 85 + "__id__": 86 }, "_enabled": true, "__prefab": null, @@ -3234,16 +3249,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 81 + "__id__": 82 }, "_children": [], "_active": true, "_components": [ { - "__id__": 90 + "__id__": 91 }, { - "__id__": 91 + "__id__": 92 } ], "_prefab": null, @@ -3282,7 +3297,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 89 + "__id__": 90 }, "_enabled": true, "__prefab": null, @@ -3304,7 +3319,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 89 + "__id__": 90 }, "_enabled": true, "__prefab": null, @@ -3366,19 +3381,19 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 81 + "__id__": 82 }, "_children": [], "_active": false, "_components": [ - { - "__id__": 93 - }, { "__id__": 94 }, { "__id__": 95 + }, + { + "__id__": 96 } ], "_prefab": null, @@ -3417,7 +3432,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 92 + "__id__": 93 }, "_enabled": true, "__prefab": null, @@ -3439,7 +3454,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 92 + "__id__": 93 }, "_enabled": true, "__prefab": null, @@ -3478,7 +3493,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 92 + "__id__": 93 }, "_enabled": true, "__prefab": null, @@ -3501,7 +3516,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 81 + "__id__": 82 }, "_enabled": true, "__prefab": null, @@ -3523,7 +3538,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 81 + "__id__": 82 }, "_enabled": true, "__prefab": null, @@ -3551,7 +3566,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 81 + "__id__": 82 }, "_enabled": true, "__prefab": null, @@ -3583,28 +3598,28 @@ }, "_children": [ { - "__id__": 100 + "__id__": 101 }, { - "__id__": 103 + "__id__": 104 }, { - "__id__": 107 + "__id__": 108 }, { - "__id__": 110 + "__id__": 111 } ], "_active": true, "_components": [ - { - "__id__": 114 - }, { "__id__": 115 }, { "__id__": 116 + }, + { + "__id__": 117 } ], "_prefab": null, @@ -3643,16 +3658,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 99 + "__id__": 100 }, "_children": [], "_active": true, "_components": [ { - "__id__": 101 + "__id__": 102 }, { - "__id__": 102 + "__id__": 103 } ], "_prefab": null, @@ -3691,7 +3706,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 100 + "__id__": 101 }, "_enabled": true, "__prefab": null, @@ -3713,7 +3728,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 100 + "__id__": 101 }, "_enabled": true, "__prefab": null, @@ -3725,19 +3740,19 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 99 + "__id__": 100 }, "_children": [], "_active": true, "_components": [ - { - "__id__": 104 - }, { "__id__": 105 }, { "__id__": 106 + }, + { + "__id__": 107 } ], "_prefab": null, @@ -3776,7 +3791,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 103 + "__id__": 104 }, "_enabled": true, "__prefab": null, @@ -3798,7 +3813,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 103 + "__id__": 104 }, "_enabled": true, "__prefab": null, @@ -3837,7 +3852,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 103 + "__id__": 104 }, "_enabled": true, "__prefab": null, @@ -3868,16 +3883,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 99 + "__id__": 100 }, "_children": [], "_active": true, "_components": [ { - "__id__": 108 + "__id__": 109 }, { - "__id__": 109 + "__id__": 110 } ], "_prefab": null, @@ -3916,7 +3931,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 107 + "__id__": 108 }, "_enabled": true, "__prefab": null, @@ -3938,7 +3953,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 107 + "__id__": 108 }, "_enabled": true, "__prefab": null, @@ -4000,19 +4015,19 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 99 + "__id__": 100 }, "_children": [], "_active": false, "_components": [ - { - "__id__": 111 - }, { "__id__": 112 }, { "__id__": 113 + }, + { + "__id__": 114 } ], "_prefab": null, @@ -4051,7 +4066,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 110 + "__id__": 111 }, "_enabled": true, "__prefab": null, @@ -4073,7 +4088,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 110 + "__id__": 111 }, "_enabled": true, "__prefab": null, @@ -4112,7 +4127,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 110 + "__id__": 111 }, "_enabled": true, "__prefab": null, @@ -4135,7 +4150,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 99 + "__id__": 100 }, "_enabled": true, "__prefab": null, @@ -4157,7 +4172,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 99 + "__id__": 100 }, "_enabled": true, "__prefab": null, @@ -4185,7 +4200,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 99 + "__id__": 100 }, "_enabled": true, "__prefab": null, @@ -4217,28 +4232,28 @@ }, "_children": [ { - "__id__": 118 + "__id__": 119 }, { - "__id__": 121 + "__id__": 122 }, { - "__id__": 125 + "__id__": 126 }, { - "__id__": 128 + "__id__": 129 } ], "_active": true, "_components": [ - { - "__id__": 132 - }, { "__id__": 133 }, { "__id__": 134 + }, + { + "__id__": 135 } ], "_prefab": null, @@ -4277,16 +4292,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 117 + "__id__": 118 }, "_children": [], "_active": true, "_components": [ { - "__id__": 119 + "__id__": 120 }, { - "__id__": 120 + "__id__": 121 } ], "_prefab": null, @@ -4325,7 +4340,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 118 + "__id__": 119 }, "_enabled": true, "__prefab": null, @@ -4347,7 +4362,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 118 + "__id__": 119 }, "_enabled": true, "__prefab": null, @@ -4359,19 +4374,19 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 117 + "__id__": 118 }, "_children": [], "_active": true, "_components": [ - { - "__id__": 122 - }, { "__id__": 123 }, { "__id__": 124 + }, + { + "__id__": 125 } ], "_prefab": null, @@ -4410,7 +4425,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 121 + "__id__": 122 }, "_enabled": true, "__prefab": null, @@ -4432,7 +4447,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 121 + "__id__": 122 }, "_enabled": true, "__prefab": null, @@ -4471,7 +4486,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 121 + "__id__": 122 }, "_enabled": true, "__prefab": null, @@ -4502,16 +4517,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 117 + "__id__": 118 }, "_children": [], "_active": true, "_components": [ { - "__id__": 126 + "__id__": 127 }, { - "__id__": 127 + "__id__": 128 } ], "_prefab": null, @@ -4550,7 +4565,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 125 + "__id__": 126 }, "_enabled": true, "__prefab": null, @@ -4572,7 +4587,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 125 + "__id__": 126 }, "_enabled": true, "__prefab": null, @@ -4634,19 +4649,19 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 117 + "__id__": 118 }, "_children": [], "_active": false, "_components": [ - { - "__id__": 129 - }, { "__id__": 130 }, { "__id__": 131 + }, + { + "__id__": 132 } ], "_prefab": null, @@ -4685,7 +4700,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 128 + "__id__": 129 }, "_enabled": true, "__prefab": null, @@ -4707,7 +4722,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 128 + "__id__": 129 }, "_enabled": true, "__prefab": null, @@ -4746,7 +4761,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 128 + "__id__": 129 }, "_enabled": true, "__prefab": null, @@ -4769,7 +4784,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 117 + "__id__": 118 }, "_enabled": true, "__prefab": null, @@ -4791,7 +4806,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 117 + "__id__": 118 }, "_enabled": true, "__prefab": null, @@ -4819,7 +4834,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 117 + "__id__": 118 }, "_enabled": true, "__prefab": null, @@ -4851,22 +4866,22 @@ }, "_children": [ { - "__id__": 136 + "__id__": 137 }, { - "__id__": 140 + "__id__": 141 } ], "_active": true, "_components": [ - { - "__id__": 143 - }, { "__id__": 144 }, { "__id__": 145 + }, + { + "__id__": 146 } ], "_prefab": null, @@ -4905,19 +4920,19 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 135 + "__id__": 136 }, "_children": [], "_active": true, "_components": [ - { - "__id__": 137 - }, { "__id__": 138 }, { "__id__": 139 + }, + { + "__id__": 140 } ], "_prefab": null, @@ -4956,7 +4971,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 136 + "__id__": 137 }, "_enabled": true, "__prefab": null, @@ -4978,7 +4993,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 136 + "__id__": 137 }, "_enabled": true, "__prefab": null, @@ -5017,7 +5032,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 136 + "__id__": 137 }, "_enabled": true, "__prefab": null, @@ -5044,16 +5059,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 135 + "__id__": 136 }, "_children": [], "_active": false, "_components": [ { - "__id__": 141 + "__id__": 142 }, { - "__id__": 142 + "__id__": 143 } ], "_prefab": null, @@ -5092,7 +5107,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 140 + "__id__": 141 }, "_enabled": true, "__prefab": null, @@ -5114,7 +5129,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 140 + "__id__": 141 }, "_enabled": true, "__prefab": null, @@ -5176,7 +5191,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 135 + "__id__": 136 }, "_enabled": true, "__prefab": null, @@ -5198,7 +5213,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 135 + "__id__": 136 }, "_enabled": true, "__prefab": null, @@ -5226,7 +5241,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 135 + "__id__": 136 }, "_enabled": true, "__prefab": null, @@ -5258,22 +5273,22 @@ }, "_children": [ { - "__id__": 147 + "__id__": 148 }, { - "__id__": 151 + "__id__": 152 } ], "_active": true, "_components": [ - { - "__id__": 154 - }, { "__id__": 155 }, { "__id__": 156 + }, + { + "__id__": 157 } ], "_prefab": null, @@ -5312,19 +5327,19 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 146 + "__id__": 147 }, "_children": [], "_active": true, "_components": [ - { - "__id__": 148 - }, { "__id__": 149 }, { "__id__": 150 + }, + { + "__id__": 151 } ], "_prefab": null, @@ -5363,7 +5378,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 147 + "__id__": 148 }, "_enabled": true, "__prefab": null, @@ -5385,7 +5400,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 147 + "__id__": 148 }, "_enabled": true, "__prefab": null, @@ -5424,7 +5439,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 147 + "__id__": 148 }, "_enabled": true, "__prefab": null, @@ -5451,16 +5466,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 146 + "__id__": 147 }, "_children": [], "_active": false, "_components": [ { - "__id__": 152 + "__id__": 153 }, { - "__id__": 153 + "__id__": 154 } ], "_prefab": null, @@ -5499,7 +5514,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 151 + "__id__": 152 }, "_enabled": true, "__prefab": null, @@ -5521,7 +5536,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 151 + "__id__": 152 }, "_enabled": true, "__prefab": null, @@ -5583,7 +5598,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 146 + "__id__": 147 }, "_enabled": true, "__prefab": null, @@ -5605,7 +5620,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 146 + "__id__": 147 }, "_enabled": true, "__prefab": null, @@ -5633,7 +5648,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 146 + "__id__": 147 }, "_enabled": true, "__prefab": null, @@ -5665,28 +5680,28 @@ }, "_children": [ { - "__id__": 158 + "__id__": 159 }, { - "__id__": 161 + "__id__": 162 }, { - "__id__": 165 + "__id__": 166 }, { - "__id__": 168 + "__id__": 169 } ], "_active": true, "_components": [ - { - "__id__": 172 - }, { "__id__": 173 }, { "__id__": 174 + }, + { + "__id__": 175 } ], "_prefab": null, @@ -5725,16 +5740,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 157 + "__id__": 158 }, "_children": [], "_active": true, "_components": [ { - "__id__": 159 + "__id__": 160 }, { - "__id__": 160 + "__id__": 161 } ], "_prefab": null, @@ -5773,7 +5788,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 158 + "__id__": 159 }, "_enabled": true, "__prefab": null, @@ -5795,7 +5810,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 158 + "__id__": 159 }, "_enabled": true, "__prefab": null, @@ -5807,19 +5822,19 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 157 + "__id__": 158 }, "_children": [], "_active": true, "_components": [ - { - "__id__": 162 - }, { "__id__": 163 }, { "__id__": 164 + }, + { + "__id__": 165 } ], "_prefab": null, @@ -5858,7 +5873,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 161 + "__id__": 162 }, "_enabled": true, "__prefab": null, @@ -5880,7 +5895,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 161 + "__id__": 162 }, "_enabled": true, "__prefab": null, @@ -5919,7 +5934,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 161 + "__id__": 162 }, "_enabled": true, "__prefab": null, @@ -5950,16 +5965,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 157 + "__id__": 158 }, "_children": [], "_active": true, "_components": [ { - "__id__": 166 + "__id__": 167 }, { - "__id__": 167 + "__id__": 168 } ], "_prefab": null, @@ -5998,7 +6013,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 165 + "__id__": 166 }, "_enabled": true, "__prefab": null, @@ -6020,7 +6035,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 165 + "__id__": 166 }, "_enabled": true, "__prefab": null, @@ -6082,19 +6097,19 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 157 + "__id__": 158 }, "_children": [], "_active": false, "_components": [ - { - "__id__": 169 - }, { "__id__": 170 }, { "__id__": 171 + }, + { + "__id__": 172 } ], "_prefab": null, @@ -6133,7 +6148,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 168 + "__id__": 169 }, "_enabled": true, "__prefab": null, @@ -6155,7 +6170,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 168 + "__id__": 169 }, "_enabled": true, "__prefab": null, @@ -6194,7 +6209,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 168 + "__id__": 169 }, "_enabled": true, "__prefab": null, @@ -6217,7 +6232,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 157 + "__id__": 158 }, "_enabled": true, "__prefab": null, @@ -6239,7 +6254,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 157 + "__id__": 158 }, "_enabled": true, "__prefab": null, @@ -6267,7 +6282,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 157 + "__id__": 158 }, "_enabled": true, "__prefab": null, @@ -6299,28 +6314,28 @@ }, "_children": [ { - "__id__": 176 + "__id__": 177 }, { - "__id__": 179 + "__id__": 180 }, { - "__id__": 183 + "__id__": 184 }, { - "__id__": 186 + "__id__": 187 } ], "_active": true, "_components": [ - { - "__id__": 190 - }, { "__id__": 191 }, { "__id__": 192 + }, + { + "__id__": 193 } ], "_prefab": null, @@ -6359,16 +6374,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 175 + "__id__": 176 }, "_children": [], "_active": true, "_components": [ { - "__id__": 177 + "__id__": 178 }, { - "__id__": 178 + "__id__": 179 } ], "_prefab": null, @@ -6407,7 +6422,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 176 + "__id__": 177 }, "_enabled": true, "__prefab": null, @@ -6429,7 +6444,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 176 + "__id__": 177 }, "_enabled": true, "__prefab": null, @@ -6441,19 +6456,19 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 175 + "__id__": 176 }, "_children": [], "_active": true, "_components": [ - { - "__id__": 180 - }, { "__id__": 181 }, { "__id__": 182 + }, + { + "__id__": 183 } ], "_prefab": null, @@ -6492,7 +6507,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 179 + "__id__": 180 }, "_enabled": true, "__prefab": null, @@ -6514,7 +6529,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 179 + "__id__": 180 }, "_enabled": true, "__prefab": null, @@ -6553,7 +6568,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 179 + "__id__": 180 }, "_enabled": true, "__prefab": null, @@ -6584,16 +6599,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 175 + "__id__": 176 }, "_children": [], "_active": true, "_components": [ { - "__id__": 184 + "__id__": 185 }, { - "__id__": 185 + "__id__": 186 } ], "_prefab": null, @@ -6632,7 +6647,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 183 + "__id__": 184 }, "_enabled": true, "__prefab": null, @@ -6654,7 +6669,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 183 + "__id__": 184 }, "_enabled": true, "__prefab": null, @@ -6716,19 +6731,19 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 175 + "__id__": 176 }, "_children": [], "_active": false, "_components": [ - { - "__id__": 187 - }, { "__id__": 188 }, { "__id__": 189 + }, + { + "__id__": 190 } ], "_prefab": null, @@ -6767,7 +6782,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 186 + "__id__": 187 }, "_enabled": true, "__prefab": null, @@ -6789,7 +6804,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 186 + "__id__": 187 }, "_enabled": true, "__prefab": null, @@ -6828,7 +6843,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 186 + "__id__": 187 }, "_enabled": true, "__prefab": null, @@ -6851,7 +6866,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 175 + "__id__": 176 }, "_enabled": true, "__prefab": null, @@ -6873,7 +6888,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 175 + "__id__": 176 }, "_enabled": true, "__prefab": null, @@ -6901,7 +6916,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 175 + "__id__": 176 }, "_enabled": true, "__prefab": null, @@ -6933,28 +6948,28 @@ }, "_children": [ { - "__id__": 194 + "__id__": 195 }, { - "__id__": 197 + "__id__": 198 }, { - "__id__": 201 + "__id__": 202 }, { - "__id__": 204 + "__id__": 205 } ], "_active": true, "_components": [ - { - "__id__": 208 - }, { "__id__": 209 }, { "__id__": 210 + }, + { + "__id__": 211 } ], "_prefab": null, @@ -6993,16 +7008,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 193 + "__id__": 194 }, "_children": [], "_active": true, "_components": [ { - "__id__": 195 + "__id__": 196 }, { - "__id__": 196 + "__id__": 197 } ], "_prefab": null, @@ -7041,7 +7056,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 194 + "__id__": 195 }, "_enabled": true, "__prefab": null, @@ -7063,7 +7078,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 194 + "__id__": 195 }, "_enabled": true, "__prefab": null, @@ -7075,19 +7090,19 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 193 + "__id__": 194 }, "_children": [], "_active": true, "_components": [ - { - "__id__": 198 - }, { "__id__": 199 }, { "__id__": 200 + }, + { + "__id__": 201 } ], "_prefab": null, @@ -7126,7 +7141,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 197 + "__id__": 198 }, "_enabled": true, "__prefab": null, @@ -7148,7 +7163,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 197 + "__id__": 198 }, "_enabled": true, "__prefab": null, @@ -7187,7 +7202,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 197 + "__id__": 198 }, "_enabled": true, "__prefab": null, @@ -7218,16 +7233,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 193 + "__id__": 194 }, "_children": [], "_active": true, "_components": [ { - "__id__": 202 + "__id__": 203 }, { - "__id__": 203 + "__id__": 204 } ], "_prefab": null, @@ -7266,7 +7281,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 201 + "__id__": 202 }, "_enabled": true, "__prefab": null, @@ -7288,7 +7303,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 201 + "__id__": 202 }, "_enabled": true, "__prefab": null, @@ -7350,19 +7365,19 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 193 + "__id__": 194 }, "_children": [], "_active": false, "_components": [ - { - "__id__": 205 - }, { "__id__": 206 }, { "__id__": 207 + }, + { + "__id__": 208 } ], "_prefab": null, @@ -7401,7 +7416,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 204 + "__id__": 205 }, "_enabled": true, "__prefab": null, @@ -7423,7 +7438,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 204 + "__id__": 205 }, "_enabled": true, "__prefab": null, @@ -7462,7 +7477,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 204 + "__id__": 205 }, "_enabled": true, "__prefab": null, @@ -7485,7 +7500,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 193 + "__id__": 194 }, "_enabled": true, "__prefab": null, @@ -7507,7 +7522,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 193 + "__id__": 194 }, "_enabled": true, "__prefab": null, @@ -7535,7 +7550,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 193 + "__id__": 194 }, "_enabled": true, "__prefab": null, @@ -7567,28 +7582,28 @@ }, "_children": [ { - "__id__": 212 + "__id__": 213 }, { - "__id__": 215 + "__id__": 216 }, { - "__id__": 219 + "__id__": 220 }, { - "__id__": 222 + "__id__": 223 } ], "_active": true, "_components": [ - { - "__id__": 226 - }, { "__id__": 227 }, { "__id__": 228 + }, + { + "__id__": 229 } ], "_prefab": null, @@ -7627,16 +7642,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 211 + "__id__": 212 }, "_children": [], "_active": true, "_components": [ { - "__id__": 213 + "__id__": 214 }, { - "__id__": 214 + "__id__": 215 } ], "_prefab": null, @@ -7675,7 +7690,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 212 + "__id__": 213 }, "_enabled": true, "__prefab": null, @@ -7697,7 +7712,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 212 + "__id__": 213 }, "_enabled": true, "__prefab": null, @@ -7709,19 +7724,19 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 211 + "__id__": 212 }, "_children": [], "_active": true, "_components": [ - { - "__id__": 216 - }, { "__id__": 217 }, { "__id__": 218 + }, + { + "__id__": 219 } ], "_prefab": null, @@ -7760,7 +7775,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 215 + "__id__": 216 }, "_enabled": true, "__prefab": null, @@ -7782,7 +7797,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 215 + "__id__": 216 }, "_enabled": true, "__prefab": null, @@ -7821,7 +7836,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 215 + "__id__": 216 }, "_enabled": true, "__prefab": null, @@ -7852,16 +7867,16 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 211 + "__id__": 212 }, "_children": [], "_active": true, "_components": [ { - "__id__": 220 + "__id__": 221 }, { - "__id__": 221 + "__id__": 222 } ], "_prefab": null, @@ -7900,7 +7915,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 219 + "__id__": 220 }, "_enabled": true, "__prefab": null, @@ -7922,7 +7937,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 219 + "__id__": 220 }, "_enabled": true, "__prefab": null, @@ -7984,19 +7999,19 @@ "_objFlags": 0, "__editorExtras__": {}, "_parent": { - "__id__": 211 + "__id__": 212 }, "_children": [], "_active": false, "_components": [ - { - "__id__": 223 - }, { "__id__": 224 }, { "__id__": 225 + }, + { + "__id__": 226 } ], "_prefab": null, @@ -8035,7 +8050,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 222 + "__id__": 223 }, "_enabled": true, "__prefab": null, @@ -8057,7 +8072,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 222 + "__id__": 223 }, "_enabled": true, "__prefab": null, @@ -8096,7 +8111,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 222 + "__id__": 223 }, "_enabled": true, "__prefab": null, @@ -8119,7 +8134,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 211 + "__id__": 212 }, "_enabled": true, "__prefab": null, @@ -8141,7 +8156,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 211 + "__id__": 212 }, "_enabled": true, "__prefab": null, @@ -8169,7 +8184,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 211 + "__id__": 212 }, "_enabled": true, "__prefab": null, @@ -8203,10 +8218,10 @@ "_active": false, "_components": [ { - "__id__": 230 + "__id__": 231 }, { - "__id__": 231 + "__id__": 232 } ], "_prefab": null, @@ -8245,7 +8260,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 229 + "__id__": 230 }, "_enabled": true, "__prefab": null, @@ -8267,7 +8282,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 229 + "__id__": 230 }, "_enabled": true, "__prefab": null, @@ -8312,7 +8327,7 @@ "_active": true, "_components": [ { - "__id__": 233 + "__id__": 234 } ], "_prefab": null, @@ -8351,7 +8366,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 232 + "__id__": 233 }, "_enabled": true, "__prefab": null, @@ -8375,14 +8390,14 @@ "_children": [], "_active": true, "_components": [ - { - "__id__": 235 - }, { "__id__": 236 }, { "__id__": 237 + }, + { + "__id__": 238 } ], "_prefab": null, @@ -8421,7 +8436,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 234 + "__id__": 235 }, "_enabled": true, "__prefab": null, @@ -8443,7 +8458,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 234 + "__id__": 235 }, "_enabled": true, "__prefab": null, @@ -8466,7 +8481,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 234 + "__id__": 235 }, "_enabled": true, "__prefab": null, @@ -8511,10 +8526,10 @@ "_active": false, "_components": [ { - "__id__": 239 + "__id__": 240 }, { - "__id__": 240 + "__id__": 241 } ], "_prefab": null, @@ -8553,7 +8568,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 238 + "__id__": 239 }, "_enabled": true, "__prefab": null, @@ -8575,7 +8590,7 @@ "_objFlags": 0, "__editorExtras__": {}, "node": { - "__id__": 238 + "__id__": 239 }, "_enabled": true, "__prefab": null, @@ -8663,29 +8678,29 @@ { "__type__": "cc.SceneGlobals", "ambient": { - "__id__": 244 - }, - "shadows": { "__id__": 245 }, - "_skybox": { + "shadows": { "__id__": 246 }, - "fog": { + "_skybox": { "__id__": 247 }, - "octree": { + "fog": { "__id__": 248 }, - "skin": { + "octree": { "__id__": 249 }, - "lightProbeInfo": { + "skin": { "__id__": 250 }, - "postSettings": { + "lightProbeInfo": { "__id__": 251 }, + "postSettings": { + "__id__": 252 + }, "bakedWithStationaryMainLight": false, "bakedWithHighpLightmap": false }, diff --git a/assets/scripts/PlayerController.ts b/assets/scripts/PlayerController.ts index e4d2e5a..a8d4c3f 100644 --- a/assets/scripts/PlayerController.ts +++ b/assets/scripts/PlayerController.ts @@ -152,7 +152,6 @@ export class PlayerController extends Component { private onTouchStart(event: EventTouch) { if (this.activePopup) { - this.hideActivePopup(); return; } @@ -422,14 +421,13 @@ export class PlayerController extends Component { this.lastTargetPosition.set(targetPos); this.lastPosition.set(currentPos); + // 在移动前计算并设置方向(只计算一次) + this.updateMovementDirectionOnce(currentPos, targetPos); + // 使用缓动移动到目标位置 this.moveTween = tween(this.player) .to(moveTime, { position: targetPos }, { easing: 'linear', // 使用线性插值,保持匀速移动 - onUpdate: (target: Node) => { - // 在移动过程中更新动画方向 - this.updateMovementDirection(target.position); - }, onComplete: () => { this.currentPathIndex++; this.moveToNextWaypoint(); @@ -465,6 +463,11 @@ export class PlayerController extends Component { console.log(`开始平滑路径移动,总距离: ${totalDistance.toFixed(2)}, 总时间: ${totalTime.toFixed(2)}秒`); + // 在移动前计算并设置方向(只计算一次) + const startPos = this.player.position.clone(); + const finalTargetPos = this.currentPath[this.currentPath.length - 1]; + this.updateMovementDirectionOnce(startPos, finalTargetPos); + // 创建连续的路径移动 this.moveTween = tween(this.player) .to(totalTime, { position: this.currentPath[this.currentPath.length - 1] }, { @@ -474,7 +477,6 @@ export class PlayerController extends Component { const currentPos = this.getPositionOnPath(ratio); if (currentPos) { target.position = currentPos; - this.updateMovementDirection(currentPos); } }, onComplete: () => { @@ -531,23 +533,17 @@ export class PlayerController extends Component { } /** - * 在移动过程中更新动画方向 + * 在移动开始前计算一次方向(梦幻西游风格:点击一次屏幕只计算一次方向) + * 算法:优先判断水平方向(左/右),只有当水平方向不明显时才判断垂直方向 */ - private updateMovementDirection(currentPos: Vec3) { - if (!this.player || this.currentPath.length === 0) { + private updateMovementDirectionOnce(startPos: Vec3, targetPos: Vec3) { + if (!this.player) { return; } - // 计算移动方向(基于下一路径点) - let targetPos: Vec3; - if (this.currentPathIndex < this.currentPath.length - 1) { - targetPos = this.currentPath[this.currentPathIndex + 1]; - } else { - targetPos = this.currentPath[this.currentPath.length - 1]; - } - - const deltaX = targetPos.x - currentPos.x; - const deltaY = targetPos.y - currentPos.y; + // 计算移动方向(基于起始位置和目标位置) + const deltaX = targetPos.x - startPos.x; + const deltaY = targetPos.y - startPos.y; // 如果移动距离很小,不更新动画 const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY); @@ -555,17 +551,19 @@ export class PlayerController extends Component { return; } - // 计算主要移动方向 - const absX = Math.abs(deltaX); - const absY = Math.abs(deltaY); + // 梦幻西游方向判断逻辑: + // 1. 优先判断水平方向:左上、左下、左都算左边;右上、右下、右都算右边 + // 2. 只有当水平方向不明显时(接近垂直),才判断垂直方向 - // 更新当前方向 - if (absX > absY) { - // 水平移动为主 - this.currentDirection = deltaX < 0 ? 3 : 5; + // 设置一个阈值,当水平方向的绝对值大于这个阈值时,优先判断水平方向 + const horizontalThreshold = 0.5; // 可以根据需要调整这个值 + + if (Math.abs(deltaX) > horizontalThreshold) { + // 水平方向明显,优先判断左右 + this.currentDirection = deltaX < 0 ? 3 : 5; // 3表示左,5表示右 } else { - // 垂直移动为主 - this.currentDirection = deltaY < 0 ? 3 : 5; + // 水平方向不明显,判断垂直方向 + this.currentDirection = deltaY < 0 ? 3 : 5; // 3表示上,5表示下 } // 切换到对应的动画(只传递基础动画名称) @@ -1067,8 +1065,8 @@ export class PlayerController extends Component { console.log('创建道具飞向玩家的动画'); - // 获取玩家位置 - const playerPos = this.player.position.clone(); + // 获取玩家节点的世界坐标(中心位置) + const playerWorldPos = this.player.worldPosition.clone(); // 创建所有道具的飞行动画承诺 const flyPromises: Promise[] = []; @@ -1081,7 +1079,7 @@ export class PlayerController extends Component { const originalPos = prop.position.clone(); // 计算飞行时间(根据距离调整) - const distance = Vec3.distance(originalPos, playerPos); + const distance = Vec3.distance(originalPos, playerWorldPos); const flyDuration = Math.max(0.5, distance / 500); // 最少0.5秒,速度500像素/秒 // 添加延迟,让道具依次飞向玩家 @@ -1093,9 +1091,30 @@ export class PlayerController extends Component { // 创建飞行动画的承诺 const flyPromise = new Promise((resolve) => { this.scheduleOnce(() => { + // 将玩家的世界坐标转换为道具父节点的本地坐标 + const propParent = prop.parent; + let targetPos: Vec3; + + if (propParent) { + const parentTransform = propParent.getComponent(UITransform); + if (parentTransform) { + targetPos = parentTransform.convertToNodeSpaceAR(playerWorldPos); + } else { + // 如果没有UITransform组件,使用简单的坐标转换 + targetPos = new Vec3( + playerWorldPos.x - propParent.worldPosition.x, + playerWorldPos.y - propParent.worldPosition.y, + playerWorldPos.z - propParent.worldPosition.z + ); + } + } else { + // 如果道具没有父节点,直接使用世界坐标 + targetPos = playerWorldPos.clone(); + } + tween(prop) .to(flyDuration, { - position: new Vec3(playerPos.x, playerPos.y, playerPos.z) + position: targetPos }, { easing: 'quadOut', onComplete: () => {