Fix drops on enemies and treasure rooms

This commit is contained in:
Marco 2025-05-01 14:43:30 +02:00
commit 8d71a59d84
25 changed files with 81 additions and 40 deletions

View file

@ -12,11 +12,11 @@ public partial class ItemDrop : RigidBody2D
private RandomNumberGenerator _rng = new();
public override void _Ready()
{
PackedScene dropScene = GD.Load<PackedScene>(ItemToDrop.DropScenePath);
Node dropInstance = dropScene.Instantiate();
AddChild(dropInstance);
dropInstance.Owner = this;
var dropInstance = ItemToDrop.Spawn(this, true);
//Node dropInstance = dropScene.Instantiate();
//AddChild(dropInstance);
CallDeferred(MethodName.DelayedAddOwner, dropInstance);
float angle = _rng.RandfRange(0, Mathf.Tau); // 0 to 2π
Vector2 direction = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)).Normalized();
@ -24,4 +24,9 @@ public partial class ItemDrop : RigidBody2D
// Apply impulse in that direction
ApplyImpulse(direction * StartingSpeed);
}
private void DelayedAddOwner(Node2D node)
{
node.Owner = this;
}
}