diff --git a/addons/block_code/simple_spawner/simple_spawner.gd b/addons/block_code/simple_spawner/simple_spawner.gd index 8e63a512..78b2b5da 100644 --- a/addons/block_code/simple_spawner/simple_spawner.gd +++ b/addons/block_code/simple_spawner/simple_spawner.gd @@ -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 parent node: +## - If the spawned scene is a RigidBody2D, the linear velocity and constant forces +## are rotated according to the parent node rotation. +## - If the spawned scene is a Node2D, the rotation is copied from the parent node. +@export var rotate_with_parent: bool = false + var _timer: Timer var _spawned_scenes: Array[Node] @@ -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_parent and get_parent() and get_parent() is Node2D: + if spawned is RigidBody2D: + spawned.linear_velocity = spawned.linear_velocity.rotated(get_parent().rotation) + spawned.constant_force = spawned.constant_force.rotated(get_parent().rotation) + elif spawned is Node2D: + spawned.rotate(get_parent().rotation) match spawn_parent: SpawnParent.THIS: add_child(spawned)