Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimpleSpawner: Add "rotate with parent" property #292

Closed
wants to merge 2 commits into from
Closed
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
12 changes: 12 additions & 0 deletions addons/block_code/simple_spawner/simple_spawner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ enum LimitBehavior { REPLACE, NO_SPAWN }
## - No Spawn: No spawn happens until any spawned scene is removed by other means.
@export var limit_behavior: LimitBehavior

## Whether the scene being spawned is rotated according to the SimpleSpawner node:
## - If the spawned scene is a RigidBody2D, the linear velocity and constant forces
## are rotated according to the SimpleSpawner node global rotation.
## - If the spawned scene is a Node2D, the rotation is copied from the SimpleSpawner node.
@export var rotate_with_spawner: bool = true

var _timer: Timer
var _spawned_scenes: Array[Node]

Expand Down Expand Up @@ -99,6 +105,12 @@ func spawn_once():
var scene: PackedScene = scenes.pick_random()
var spawned = scene.instantiate()
_spawned_scenes.push_back(spawned)
if rotate_with_spawner:
if spawned is RigidBody2D:
spawned.linear_velocity = spawned.linear_velocity.rotated(global_rotation)
spawned.constant_force = spawned.constant_force.rotated(global_rotation)
elif spawned is Node2D:
spawned.rotate(global_rotation)
match spawn_parent:
SpawnParent.THIS:
add_child(spawned)
Expand Down