Shoot through

This commit is contained in:
MaddoScientisto 2024-05-26 11:40:35 +02:00
commit 92a82b05df
6 changed files with 31 additions and 42 deletions

View file

@ -24,4 +24,5 @@ editor_description = "Player Bullet"
[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."] [node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."]
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"] [connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"]

View file

@ -35,10 +35,10 @@ public partial class fragola : RigidBody2D
Debug.WriteLine("Collision area"); Debug.WriteLine("Collision area");
EmitSignal(SignalName.Hit); EmitSignal(SignalName.Hit);
if (_isAlive) if (_isAlive)
{ {
Explode(); Explode();
} }
} }
private void Explode() private void Explode()

View file

@ -135,9 +135,10 @@ animations = [{
[node name="Player" type="CharacterBody2D" node_paths=PackedStringArray("Muzzle") groups=["player"]] [node name="Player" type="CharacterBody2D" node_paths=PackedStringArray("Muzzle") groups=["player"]]
collision_layer = 2 collision_layer = 2
collision_mask = 3 collision_mask = 35
script = ExtResource("1_m27vu") script = ExtResource("1_m27vu")
Speed = 2000 Speed = 2500
CrosshairDistance = 20.0
BulletScene = ExtResource("2_ov36d") BulletScene = ExtResource("2_ov36d")
Muzzle = NodePath("Muzzle") Muzzle = NodePath("Muzzle")
metadata/_edit_group_ = true metadata/_edit_group_ = true

File diff suppressed because one or more lines are too long

View file

@ -20,10 +20,10 @@ public partial class Bullet : Area2D
//private void OnBodyEntered(Node body) //private void OnBodyEntered(Node body)
//{ //{
// When a body is entered, invoke the event and pass the collided body // When a body is entered, invoke the event and pass the collided body
// BulletHit?.Invoke(body); // BulletHit?.Invoke(body);
// Then remove the bullet // Then remove the bullet
// QueueFree(); // QueueFree();
//} //}
@ -40,7 +40,7 @@ public partial class Bullet : Area2D
// Called every frame. 'delta' is the elapsed time since the previous frame. // Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta) public override void _Process(double delta)
{ {
this.Position += ((float) (Speed * delta) * _direction); this.Position += ((float)(Speed * delta) * _direction);
} }
private void _on_visible_on_screen_notifier_2d_screen_exited() private void _on_visible_on_screen_notifier_2d_screen_exited()
@ -49,7 +49,19 @@ public partial class Bullet : Area2D
QueueFree(); QueueFree();
} }
private void _on_body_entered(Node2D body)
{
if (body.IsInGroup("Solid"))
{
Debug.WriteLine("Collision");
QueueFree();
}
}
} }

View file

@ -72,6 +72,7 @@ shoot={
2d_physics/layer_3="items" 2d_physics/layer_3="items"
2d_physics/layer_4="bullets" 2d_physics/layer_4="bullets"
2d_physics/layer_5="enemies" 2d_physics/layer_5="enemies"
2d_physics/layer_6="shoot-through"
[physics] [physics]