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="."]
[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"]

View file

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

View file

@ -135,9 +135,10 @@ animations = [{
[node name="Player" type="CharacterBody2D" node_paths=PackedStringArray("Muzzle") groups=["player"]]
collision_layer = 2
collision_mask = 3
collision_mask = 35
script = ExtResource("1_m27vu")
Speed = 2000
Speed = 2500
CrosshairDistance = 20.0
BulletScene = ExtResource("2_ov36d")
Muzzle = NodePath("Muzzle")
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)
//{
// 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);
// Then remove the bullet
// Then remove the bullet
// QueueFree();
//}
@ -40,7 +40,7 @@ public partial class Bullet : Area2D
// Called every frame. 'delta' is the elapsed time since the previous frame.
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()
@ -49,7 +49,19 @@ public partial class Bullet : Area2D
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_4="bullets"
2d_physics/layer_5="enemies"
2d_physics/layer_6="shoot-through"
[physics]