diff --git a/DungeonShooting_Godot/prefab/effect/BulletSmoke.tscn b/DungeonShooting_Godot/prefab/effect/BulletSmoke.tscn index 31d008e..816aebc 100644 --- a/DungeonShooting_Godot/prefab/effect/BulletSmoke.tscn +++ b/DungeonShooting_Godot/prefab/effect/BulletSmoke.tscn @@ -77,6 +77,7 @@ [node name="BulletSmoke" type="Particles2D"] material = SubResource( 1 ) +scale = Vector2( 0.8, 0.8 ) emitting = false lifetime = 0.4 one_shot = true diff --git a/DungeonShooting_Godot/prefab/weapon/bullet/Bullet.tscn b/DungeonShooting_Godot/prefab/weapon/bullet/Bullet.tscn index 7f6d2a0..4f1a043 100644 --- a/DungeonShooting_Godot/prefab/weapon/bullet/Bullet.tscn +++ b/DungeonShooting_Godot/prefab/weapon/bullet/Bullet.tscn @@ -61,6 +61,7 @@ [node name="Bullet" type="Node"] script = ExtResource( 1 ) +CollisionMask = 1 [node name="ShadowSprite" type="Sprite" parent="."] material = SubResource( 3 ) @@ -72,9 +73,11 @@ frames = SubResource( 1 ) [node name="Collision" type="CollisionShape2D" parent="."] -position = Vector2( 1.5, 0 ) +position = Vector2( 2, 0 ) +shape = SubResource( 2 ) [node name="CollisionArea" type="Area2D" parent="."] +visible = false collision_layer = 0 collision_mask = 0 diff --git a/DungeonShooting_Godot/src/game/item/weapon/bullet/Bullet.cs b/DungeonShooting_Godot/src/game/item/weapon/bullet/Bullet.cs index 074ffbe..1a0db47 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/bullet/Bullet.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/bullet/Bullet.cs @@ -25,9 +25,6 @@ CollisionArea = GetNode("CollisionArea"); CollisionArea.CollisionMask = targetLayer; CollisionArea.Connect("area_entered", this, nameof(OnArea2dEntered)); - CollisionArea.Connect("body_entered", this, nameof(OnBodyEntered)); - - Collision.Disabled = true; MaxDistance = maxDistance; Position = position; @@ -46,7 +43,19 @@ { base._PhysicsProcess(delta); //移动 - Position += new Vector2(FlySpeed * delta, 0).Rotated(Rotation); + var kinematicCollision = MoveAndCollide(new Vector2(FlySpeed * delta, 0).Rotated(Rotation)); + if (kinematicCollision != null) + { + //创建粒子特效 + var packedScene = ResourceManager.Load(ResourcePath.prefab_effect_BulletSmoke_tscn); + var smoke = packedScene.Instance(); + smoke.Position = Position; + smoke.Rotation = kinematicCollision.Normal.Angle(); + GameApplication.Instance.Room.GetRoot(true).AddChild(smoke); + + Destroy(); + return; + } //距离太大, 自动销毁 CurrFlyDistance += FlySpeed * delta; if (CurrFlyDistance >= MaxDistance) @@ -61,37 +70,7 @@ if (role != null) { role.Hurt(1); - - //播放受击动画 - // Node2D hit = ResourceManager.Load(ResourcePath.prefab_effect_Hit_tscn).Instance(); - // hit.RotationDegrees = Utils.RandRangeInt(0, 360); - // hit.GlobalPosition = GlobalPosition; - // GameApplication.Instance.Room.GetRoot(true).AddChild(hit); - - DoDestroy(); + Destroy(); } } - - private void OnBodyEntered(Node2D other) - { - if (!(other is Role)) - { - DoDestroy(); - } - } - - private void DoDestroy() - { - // SpecialEffectManager.Play(ResourcePath.resource_effects_Hit_tres, "default", GlobalPosition, - // Mathf.Deg2Rad(Utils.RandRangeInt(0, 360)), Vector2.One, new Vector2(1, 11), 0); - - //创建粒子特效 - var packedScene = ResourceManager.Load(ResourcePath.prefab_effect_BulletSmoke_tscn); - var smoke = packedScene.Instance(); - smoke.Position = Position; - smoke.Rotation = Rotation - Mathf.Pi; - GameApplication.Instance.Room.GetRoot(true).AddChild(smoke); - - Destroy(); - } } \ No newline at end of file