Skip to content

Commit

Permalink
oops + better offset
Browse files Browse the repository at this point in the history
  • Loading branch information
CaptainSqrBeard committed Dec 21, 2024
1 parent 8e5e756 commit 1b6cb20
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public sealed partial class FromTileCrafterComponent : Component
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float Delay = 1f;

/// <summary>
/// How far spawned item can offset from tile center
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float Spread = 0.3f;
}

[Serializable, NetSerializable]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ private void OnFromTileCraftComplete(Entity<FromTileCrafterComponent> ent, ref F
var tileRef = _maps.GetTileRef(gridUid, grid, args.GridTile);
var coords = _maps.ToCoordinates(tileRef, grid);

var spread = grid.TileSize * 0.1f;
var spread = comp.Spread * grid.TileSize;
var offset = new Vector2(
_robustRandom.NextFloat() * spread - 0.5f,
_robustRandom.NextFloat() * spread - 0.5f);
(_robustRandom.NextFloat() - 0.5f) * spread + grid.TileSize * 0.5f,
(_robustRandom.NextFloat() - 0.5f) * spread + grid.TileSize * 0.5f);

if (!_netManager.IsServer)
if (_netManager.IsServer)
Spawn(ent.Comp.EntityToSpawn, coords.Offset(offset));
}

Expand Down

0 comments on commit 1b6cb20

Please sign in to comment.