-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#11: Update projectile to use raycast instead of area2d while area2d …
…to support projectile to projectile collision. This resolves the collision problem
- Loading branch information
Danil Ko
committed
Apr 14, 2021
1 parent
828e4cf
commit 6f1862d
Showing
15 changed files
with
120 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,28 @@ | ||
[gd_scene load_steps=3 format=2] | ||
[gd_scene load_steps=4 format=2] | ||
|
||
[ext_resource path="res://projectiles/Projectile.cs" type="Script" id=1] | ||
[ext_resource path="res://effects/Explosion.tscn" type="PackedScene" id=2] | ||
[ext_resource path="res://projectiles/ProjectileArea2D.cs" type="Script" id=3] | ||
|
||
[node name="Bullet" type="Area2D"] | ||
collision_layer = 4 | ||
[node name="Projectile" type="RayCast2D"] | ||
cast_to = Vector2( 50, 0 ) | ||
collision_mask = 7 | ||
script = ExtResource( 1 ) | ||
|
||
[node name="Sprite" type="Sprite" parent="."] | ||
region_rect = Rect2( 1098, 442, 27, 17 ) | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||
|
||
[node name="Lifetime" type="Timer" parent="."] | ||
wait_time = 10.0 | ||
|
||
[node name="Explosion" parent="." instance=ExtResource( 2 )] | ||
visible = false | ||
scale = Vector2( 0.5, 0.5 ) | ||
[connection signal="area_entered" from="." to="." method="_onProjectileAreaEntered"] | ||
[connection signal="body_entered" from="." to="." method="_onProjectileBodyEntered"] | ||
|
||
[node name="ProjectileArea2D" type="Area2D" parent="."] | ||
script = ExtResource( 3 ) | ||
|
||
[node name="CollisionShape2D" type="CollisionShape2D" parent="ProjectileArea2D"] | ||
[connection signal="timeout" from="Lifetime" to="." method="_onLifetimeTimeout"] | ||
[connection signal="animation_finished" from="Explosion" to="." method="_OnExplosionAnimationFinished"] | ||
[connection signal="area_entered" from="ProjectileArea2D" to="ProjectileArea2D" method="_onProjectileAreaEntered"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Godot; | ||
using System; | ||
|
||
public class ProjectileArea2D : Area2D | ||
{ | ||
Projectile projectile; | ||
|
||
public override void _Ready() | ||
{ | ||
projectile = (Projectile)GetParent(); | ||
} | ||
|
||
public Team.TeamCode GetTeam() | ||
{ | ||
return projectile.GetTeam(); | ||
} | ||
|
||
public void Explode() | ||
{ | ||
projectile.Explode(); | ||
} | ||
|
||
private void _onProjectileAreaEntered(Area2D body) | ||
{ | ||
// Projectile will collide | ||
if (body.HasMethod("_onProjectileAreaEntered")) | ||
{ | ||
ProjectileArea2D collider = (ProjectileArea2D)(body); | ||
|
||
// Only bullets from different team will cloide | ||
if (collider.GetTeam() != projectile.GetTeam()) | ||
{ | ||
collider.Explode(); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.