Skip to content

Add Spawner2D node - #165

Merged
Xrayez merged 16 commits into
gd3from
spawner
Dec 15, 2021
Merged

Xrayez merged 16 commits into
gd3from
spawner

Conversation

@Xrayez

@Xrayez Xrayez commented Dec 12, 2021 •

Copy link
Copy Markdown
Contributor

Resolves godotengine/godot-proposals#3651.

image

goost_spawner_2d.mp4

Features

  • Spawn nodes from scenes for scripts automatically per time step
  • Specify both spawn rate and time step
  • Can start spawning with a delay, useful for implementing spawn waves.
  • Can limit the number of nodes spawned in order to automatically stop the spawner.
  • The spawned nodes can be instantiated locally or globally, so that the spawner's position can be freely animated without affecting the transform of nodes that were already spawned.

Note that I'm not using Timer nodes for this at all, the timer logic is custom and allows for better integration and control.

Spawner3D could be implemented similarly.

To-do

Note that not everything below need to be implemented, this is rather a list of ideas.

  • Add node_spawned signal (when spawn() is called, either manually or per timer) and finished signal (when limit > 0).
  • Optional spawn sequences (add Position2D to specify additional spawn points to override the default spawn at origin).
    • Note the sequential part. The spawner would traverse each Position2D in succession deterministically. This should be useful for things like explosion sequences.
  • Spawn shapes: point (current), rectangle, circle, polygon etc.
    • This asks for adding randomization features to the class, but could be useful for effects rather than gameplay logic, yet this could be achieved with Particles2D anyways.
  • Automatic lifetime management
    • Not sure about this one, there are numerous ways to delete objects, and the condition to free nodes may be complex, but could mostly be useful for particle-like spawning of scenes. The video above makes coins manage lifetime within the coin scene instead.

Example project

https://github.com/goostengine/goost-examples/tree/gd3/2d/spawner

- There's no way to avoid code duplication with `GDCLASS`
- The implementation will likely diverge for `Spawner2D` and `Spawner3D` anyway.
This may avoid potential confusion that switching `spawning` property may pause the internal delay and spawn timers, which is not the case.
Similar to `Particles2D.local_coords`, disabled by default because this would be mostly useful for spawning enemies, projectiles etc. Pushing local transform down to children by default would also cause physics bodies to jitter.
@Xrayez Xrayez added feature 💡 New feature proposal component:scene labels Dec 12, 2021
@Xrayez Xrayez added this to the 1.2-gd3 milestone Dec 12, 2021
Similar to `RemoteTransform2D`. Those properties will be updated once upon node spawning.

The `modify` word appears to better suited in this context, because `update` implies that transform may be updated each frame, which is not the case.
Prevents error spam and makes things not to blow up!
Just a greenish circle (from navigation), better than nothing!
Allows to customize the spawn destination within the scene. This is needed in cases where node hierarchy is crucial to functionality, for example: inserting `PolyNode2D` scenes to create explosion sequences.
There's a case when editor-only code returns `nullptr`, but we shouldn't disable the spawner every time, because launching the scene will always lead to disabled spawner at run-time (when saved).

This reverts commit 2632286.
Made it work more like `Timer` now (backwards).
The signal is only emitted per time step, and not as a direct result of calling the function. This allows to prevent infinite loops when `spawn()` is called manually during `node_spawned` signal emission.
@Xrayez

Xrayez commented Dec 15, 2021

Copy link
Copy Markdown
Contributor Author

The core implementation is good enough I think, so lets merge this...

See godotengine/godot-proposals#3651 (comment), I think it makes sense to introduce SpawnMaterial in order to make this node more useful.

@Xrayez
Xrayez merged commit 1abf160 into gd3 Dec 15, 2021
@Xrayez
Xrayez deleted the spawner branch December 15, 2021 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Spawner node

1 participant