Skip to content

Commit 463bb4e

Browse files
committed
SimpleSpawner: Add "rotate with parent" property
Add yet another setting to the SimpleSpawner. This is to rotate the spawned scene according to the SimpleSpawner parent node. Useful for changing the direction of bullets spawned from a rotated object.
1 parent 2f66ee7 commit 463bb4e

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

addons/block_code/simple_spawner/simple_spawner.gd

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ enum LimitBehavior { REPLACE, NO_SPAWN }
3434
## - No Spawn: No spawn happens until any spawned scene is removed by other means.
3535
@export var limit_behavior: LimitBehavior
3636

37+
## Whether the scene being spawned is rotated according to the parent node:
38+
## - If the spawned scene is a RigidBody2D, the linear velocity and constant forces
39+
## are rotated according to the parent node rotation.
40+
## - If the spawned scene is a Node2D, the rotation is copied from the parent node.
41+
@export var rotate_with_parent: bool = false
42+
3743
var _timer: Timer
3844
var _spawned_scenes: Array[Node]
3945

@@ -99,6 +105,12 @@ func spawn_once():
99105
var scene: PackedScene = scenes.pick_random()
100106
var spawned = scene.instantiate()
101107
_spawned_scenes.push_back(spawned)
108+
if rotate_with_parent and get_parent() and get_parent() is Node2D:
109+
if spawned is RigidBody2D:
110+
spawned.linear_velocity = spawned.linear_velocity.rotated(get_parent().rotation)
111+
spawned.constant_force = spawned.constant_force.rotated(get_parent().rotation)
112+
elif spawned is Node2D:
113+
spawned.rotate(get_parent().rotation)
102114
match spawn_parent:
103115
SpawnParent.THIS:
104116
add_child(spawned)

0 commit comments

Comments
 (0)