Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions tutorials/scripting/instancing_with_signals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ given velocity:

public partial class Bullet : Area2D
{
Vector2 Velocity = new Vector2();
public Vector2 Velocity { get; set; } = Vector2.Zero;

public override void _PhysicsProcess(double delta)
{
Expand Down Expand Up @@ -111,7 +111,7 @@ Here is the code for the player using signals to emit the bullet:
public partial class Player : Sprite2D
{
[Signal]
delegate void ShootEventHandler(PackedScene bullet, Vector2 direction, Vector2 location);
public delegate void ShootEventHandler(PackedScene bullet, float direction, Vector2 location);

private PackedScene _bullet = GD.Load<PackedScene>("res://bullet.tscn");

Expand Down Expand Up @@ -147,13 +147,13 @@ In the main scene, we then connect the player's signal (it will appear in the

.. code-tab:: csharp

public void OnPlayerShoot(PackedScene bullet, Vector2 direction, Vector2 location)
private void OnPlayerShoot(PackedScene bullet, float direction, Vector2 location)
{
var bulletInstance = (Bullet)bullet.Instantiate();
AddChild(bulletInstance);
bulletInstance.Rotation = direction;
bulletInstance.Position = location;
bulletInstance.Velocity = bulletInstance.Velocity.Rotated(direction);
var spawnedBullet = bullet.Instantiate<Bullet>();
AddChild(spawnedBullet);
spawnedBullet.Rotation = direction;
spawnedBullet.Position = location;
spawnedBullet.Velocity = spawnedBullet.Velocity.Rotated(direction);
}

Now the bullets will maintain their own movement independent of the player's
Expand Down