diff --git a/DungeonShooting_Godot/src/game/role/enemy/state/AiFindAmmoState.cs b/DungeonShooting_Godot/src/game/role/enemy/state/AiFindAmmoState.cs index 4d507e6..60b02fe 100644 --- a/DungeonShooting_Godot/src/game/role/enemy/state/AiFindAmmoState.cs +++ b/DungeonShooting_Godot/src/game/role/enemy/state/AiFindAmmoState.cs @@ -112,6 +112,10 @@ (nextPos - Master.GlobalPosition - Master.NavigationPoint.Position).Normalized() * Master.MoveSpeed; } + else + { + Master.BasisVelocity = Vector2.Zero; + } } } diff --git a/DungeonShooting_Godot/src/game/role/enemy/state/AiFollowUpState.cs b/DungeonShooting_Godot/src/game/role/enemy/state/AiFollowUpState.cs index bb6e82f..3083bf6 100644 --- a/DungeonShooting_Godot/src/game/role/enemy/state/AiFollowUpState.cs +++ b/DungeonShooting_Godot/src/game/role/enemy/state/AiFollowUpState.cs @@ -70,6 +70,7 @@ //枪口指向玩家 Master.LookTargetPosition(playerPos); + if (!Master.NavigationAgent2D.IsNavigationFinished()) { //计算移动 @@ -78,6 +79,10 @@ Master.BasisVelocity = (nextPos - masterPosition - Master.NavigationPoint.Position).Normalized() * Master.MoveSpeed; } + else + { + Master.BasisVelocity = Vector2.Zero; + } //检测玩家是否在视野内 if (Master.IsInTailAfterViewRange(playerPos)) diff --git a/DungeonShooting_Godot/src/game/role/enemy/state/AiLeaveForState.cs b/DungeonShooting_Godot/src/game/role/enemy/state/AiLeaveForState.cs index d0901ab..2d60bfc 100644 --- a/DungeonShooting_Godot/src/game/role/enemy/state/AiLeaveForState.cs +++ b/DungeonShooting_Godot/src/game/role/enemy/state/AiLeaveForState.cs @@ -20,10 +20,6 @@ { Master.NavigationAgent2D.SetTargetLocation(Enemy.FindTargetPosition); } - // else if (args.Length > 0 && args[0] is Vector2 targetPos) - // { - // Master.NavigationAgent2D.SetTargetLocation(targetPos); - // } else { ChangeStateLate(prev); @@ -70,6 +66,10 @@ Master.BasisVelocity = (nextPos - Master.GlobalPosition - Master.NavigationPoint.Position).Normalized() * Master.MoveSpeed; } + else + { + Master.BasisVelocity = Vector2.Zero; + } var playerPos = GameApplication.Instance.Room.Player.GetCenterPosition(); //检测玩家是否在视野内, 如果在, 则切换到 AiTargetInView 状态 diff --git a/DungeonShooting_Godot/src/game/role/enemy/state/AiNormalState.cs b/DungeonShooting_Godot/src/game/role/enemy/state/AiNormalState.cs index 0683d8d..1e569b9 100644 --- a/DungeonShooting_Godot/src/game/role/enemy/state/AiNormalState.cs +++ b/DungeonShooting_Godot/src/game/role/enemy/state/AiNormalState.cs @@ -75,16 +75,11 @@ } else //移动中 { - //计算移动 - var nextPos = Master.NavigationAgent2D.GetNextLocation(); - Master.AnimatedSprite.Animation = AnimatorNames.Run; - Master.BasisVelocity = (nextPos - Master.GlobalPosition - Master.NavigationPoint.Position).Normalized() * - Master.MoveSpeed; - if (Master.NavigationAgent2D.IsNavigationFinished()) //到达终点 { _pauseTimer = Utils.RandRange(0.3f, 2f); _isMoveOver = true; + Master.BasisVelocity = Vector2.Zero; } else { @@ -93,6 +88,15 @@ { _pauseTimer = Utils.RandRange(0.1f, 0.5f); _isMoveOver = true; + Master.BasisVelocity = Vector2.Zero; + } + else + { + //计算移动 + var nextPos = Master.NavigationAgent2D.GetNextLocation(); + Master.AnimatedSprite.Animation = AnimatorNames.Run; + Master.BasisVelocity = (nextPos - Master.GlobalPosition - Master.NavigationPoint.Position).Normalized() * + Master.MoveSpeed; } } } diff --git a/DungeonShooting_Godot/src/game/role/enemy/state/AiSurroundState.cs b/DungeonShooting_Godot/src/game/role/enemy/state/AiSurroundState.cs index 5995c35..49644d8 100644 --- a/DungeonShooting_Godot/src/game/role/enemy/state/AiSurroundState.cs +++ b/DungeonShooting_Godot/src/game/role/enemy/state/AiSurroundState.cs @@ -77,16 +77,11 @@ } else { - //计算移动 - var nextPos = Master.NavigationAgent2D.GetNextLocation(); - Master.AnimatedSprite.Animation = AnimatorNames.Run; - Master.BasisVelocity = (nextPos - Master.GlobalPosition - Master.NavigationPoint.Position).Normalized() * - Master.MoveSpeed; - if (Master.NavigationAgent2D.IsNavigationFinished()) //到达终点 { _pauseTimer = Utils.RandRange(0f, 0.5f); _isMoveOver = true; + Master.BasisVelocity = Vector2.Zero; } else { @@ -95,6 +90,15 @@ { _pauseTimer = Utils.RandRange(0f, 0.3f); _isMoveOver = true; + Master.BasisVelocity = Vector2.Zero; + } + else + { + //计算移动 + var nextPos = Master.NavigationAgent2D.GetNextLocation(); + Master.AnimatedSprite.Animation = AnimatorNames.Run; + Master.BasisVelocity = (nextPos - Master.GlobalPosition - Master.NavigationPoint.Position).Normalized() * + Master.MoveSpeed; } } diff --git a/DungeonShooting_Godot/src/game/role/enemy/state/AiTailAfterState.cs b/DungeonShooting_Godot/src/game/role/enemy/state/AiTailAfterState.cs index d766cd2..36b872d 100644 --- a/DungeonShooting_Godot/src/game/role/enemy/state/AiTailAfterState.cs +++ b/DungeonShooting_Godot/src/game/role/enemy/state/AiTailAfterState.cs @@ -63,6 +63,7 @@ //枪口指向玩家 Master.LookTargetPosition(playerPos); + if (!Master.NavigationAgent2D.IsNavigationFinished()) { //计算移动 @@ -71,6 +72,10 @@ Master.BasisVelocity = (nextPos - Master.GlobalPosition - Master.NavigationPoint.Position).Normalized() * Master.MoveSpeed; } + else + { + Master.BasisVelocity = Vector2.Zero; + } //检测玩家是否在视野内, 如果在, 则切换到 AiTargetInView 状态 if (Master.IsInTailAfterViewRange(playerPos)) { diff --git a/DungeonShooting_Godot/src/game/room/RoomManager.cs b/DungeonShooting_Godot/src/game/room/RoomManager.cs index f96497a..aab39af 100644 --- a/DungeonShooting_Godot/src/game/room/RoomManager.cs +++ b/DungeonShooting_Godot/src/game/room/RoomManager.cs @@ -105,14 +105,14 @@ //enemy1.PickUpWeapon(WeaponManager.GetGun("1003")); enemy1.PickUpWeapon(WeaponManager.GetGun("1001")); - // for (int i = 0; i < 10; i++) - // { - // var enemyTemp = new Enemy(); - // enemyTemp.Name = "EnemyTemp" + i; - // enemyTemp.PutDown(new Vector2(150 + (i + 1) * 20, 300)); - // enemyTemp.PickUpWeapon(WeaponManager.GetGun("1003")); - // enemyTemp.PickUpWeapon(WeaponManager.GetGun("1001")); - // } + for (int i = 0; i < 10; i++) + { + var enemyTemp = new Enemy(); + enemyTemp.Name = "EnemyTemp" + i; + enemyTemp.PutDown(new Vector2(150 + (i + 1) * 20, 300)); + enemyTemp.PickUpWeapon(WeaponManager.GetGun("1003")); + enemyTemp.PickUpWeapon(WeaponManager.GetGun("1001")); + } var enemy2 = new Enemy(); enemy2.Name = "Enemy2";