@@ -41,7 +41,7 @@ given velocity:
4141
4242 public partial class Bullet : Area2D
4343 {
44- Vector2 Velocity = new Vector2() ;
44+ public Vector2 Velocity { get; set; } = Vector2.Zero ;
4545
4646 public override void _PhysicsProcess(double delta)
4747 {
@@ -111,7 +111,7 @@ Here is the code for the player using signals to emit the bullet:
111111 public partial class Player : Sprite2D
112112 {
113113 [Signal]
114- delegate void ShootEventHandler(PackedScene bullet, Vector2 direction, Vector2 location);
114+ public delegate void ShootEventHandler(PackedScene bullet, float direction, Vector2 location);
115115
116116 private PackedScene _bullet = GD.Load<PackedScene>("res://bullet.tscn");
117117
@@ -147,13 +147,13 @@ In the main scene, we then connect the player's signal (it will appear in the
147147
148148 .. code-tab :: csharp
149149
150- public void OnPlayerShoot(PackedScene bullet, Vector2 direction, Vector2 location)
150+ private void OnPlayerShoot(PackedScene bullet, float direction, Vector2 location)
151151 {
152- var bulletInstance = (Bullet) bullet.Instantiate();
153- AddChild(bulletInstance );
154- bulletInstance .Rotation = direction;
155- bulletInstance .Position = location;
156- bulletInstance .Velocity = bulletInstance .Velocity.Rotated(direction);
152+ var spawnedBullet = bullet.Instantiate<Bullet> ();
153+ AddChild(spawnedBullet );
154+ spawnedBullet .Rotation = direction;
155+ spawnedBullet .Position = location;
156+ spawnedBullet .Velocity = spawnedBullet .Velocity.Rotated(direction);
157157 }
158158
159159Now the bullets will maintain their own movement independent of the player's
0 commit comments