diff --git a/DungeonShooting_Godot/src/framework/activity/components/MoveController.cs b/DungeonShooting_Godot/src/framework/activity/components/MoveController.cs index 3d84323..fa2c05b 100644 --- a/DungeonShooting_Godot/src/framework/activity/components/MoveController.cs +++ b/DungeonShooting_Godot/src/framework/activity/components/MoveController.cs @@ -66,6 +66,14 @@ } /// + /// 获取所有外力的数量 + /// + public int GetForceCount() + { + return _forceList.Count; + } + + /// /// 快速创建一个外力, 该外力为匿名外力, 当速率变为 0 时自动销毁 /// /// 外力速率 @@ -204,7 +212,9 @@ //计算移动 ActivityInstance.Velocity = finallyVelocity; ActivityInstance.MoveAndSlide(); + //新速度 var newVelocity = ActivityInstance.Velocity; + if (newVelocity.X == 0f && _basisVelocity.X * finallyVelocity.X > 0) { _basisVelocity.X = 0; @@ -214,29 +224,45 @@ { _basisVelocity.Y = 0; } - - //调整外力速率 - for (var i = 0; i < _forceList.Count; i++) + + //是否撞到物体 + var collision = ActivityInstance.GetLastSlideCollision(); + if (collision != null) //执行反弹操作 { - var force = _forceList[i]; - if (force.Enable) + var no = collision.GetNormal().Rotated(Mathf.Pi * 0.5f); + newVelocity = (finallyVelocity - _basisVelocity).Reflect(no); + var length = _forceList.Count; + var v = newVelocity / (length / ActivityInstance.BounceStrength); + for (var i = 0; i < _forceList.Count; i++) { - var velocity = force.Velocity; - force.Velocity = new Vector2( - newVelocity.X == 0f && velocity.X * finallyVelocity.X > 0 ? 0 : velocity.X, - newVelocity.Y == 0f && velocity.Y * finallyVelocity.Y > 0 ? 0 : velocity.Y - ); - - //力速度衰减 - if (force.Resistance != 0) + _forceList[i].Velocity = v; + } + } + else //没有撞到物体 + { + //调整外力速率 + for (var i = 0; i < _forceList.Count; i++) + { + var force = _forceList[i]; + if (force.Enable) { - force.Velocity = force.Velocity.MoveToward(Vector2.Zero, force.Resistance * delta); - } + var velocity = force.Velocity; + force.Velocity = new Vector2( + newVelocity.X == 0f && velocity.X * finallyVelocity.X > 0 ? 0 : velocity.X, + newVelocity.Y == 0f && velocity.Y * finallyVelocity.Y > 0 ? 0 : velocity.Y + ); - //自动销毁 - if (force.AutoDestroy && force.Velocity == Vector2.Zero) - { - _forceList.RemoveAt(i--); + //力速度衰减 + if (force.Resistance != 0) + { + force.Velocity = force.Velocity.MoveToward(Vector2.Zero, force.Resistance * delta); + } + + //自动销毁 + if (force.AutoDestroy && force.Velocity == Vector2.Zero) + { + _forceList.RemoveAt(i--); + } } } } diff --git a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs index f7426ab..5ba1cf5 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs @@ -1083,22 +1083,4 @@ { return 1; } - - protected override void PhysicsProcessOver(float delta) - { - if (IsThrowing) - { - var collision = GetLastSlideCollision(); - //collision.GetNormal(); - if (collision != null) - { - var force = MoveController.GetForce("throw"); - if (force != null) - { - var no = collision.GetNormal().Rotated(Mathf.Pi * 0.5f); - force.Velocity = force.Velocity.Reflect(no); - } - } - } - } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/item/weapon/bullet/Bullet.cs b/DungeonShooting_Godot/src/game/item/weapon/bullet/Bullet.cs index 1d66d3f..f165172 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/bullet/Bullet.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/bullet/Bullet.cs @@ -84,6 +84,11 @@ var role = other.AsActivityObject(); if (role != null) { + var packedScene = ResourceManager.Load(ResourcePath.prefab_effect_BulletDisappear_tscn); + var node = packedScene.Instantiate(); + node.GlobalPosition = GlobalPosition; + node.AddToActivityRoot(RoomLayerEnum.YSortLayer); + role.CallDeferred(nameof(Role.Hurt), 4, Rotation); Destroy(); }