2025-01-07 18:59:37 +00:00
|
|
|
extends Node3D
|
|
|
|
|
2025-01-08 22:28:16 +00:00
|
|
|
const RAMP_SPAWN_GROUP := "RampSpawn"
|
|
|
|
const DROP_SPAWN_GROUP := "DropSpawn"
|
|
|
|
const PUTT_SPAWN_GROUP := "PuttSpawn"
|
|
|
|
|
|
|
|
const PUTT_VEC := Vector3(0, 0, 2)
|
2025-01-07 18:59:37 +00:00
|
|
|
|
|
|
|
@export var ball_scene: PackedScene
|
|
|
|
|
|
|
|
|
2025-01-08 22:28:16 +00:00
|
|
|
func spawn_balls(spawn_group: String, initial_impulse: Vector3 = Vector3.ZERO) -> void:
|
|
|
|
for spawn: Node3D in get_tree().get_nodes_in_group(spawn_group):
|
2025-01-07 18:59:37 +00:00
|
|
|
var ball: GameBall = ball_scene.instantiate()
|
|
|
|
var callback := func() -> void:
|
|
|
|
if ball.sleeping:
|
|
|
|
ball.queue_free()
|
|
|
|
ball.sleeping_state_changed.connect(callback)
|
|
|
|
spawn.add_sibling(ball)
|
|
|
|
ball.global_transform = spawn.global_transform
|
|
|
|
ball.freeze = false
|
2025-01-08 22:28:16 +00:00
|
|
|
if initial_impulse:
|
|
|
|
ball.apply_impulse(
|
|
|
|
initial_impulse,
|
|
|
|
(
|
|
|
|
initial_impulse.normalized()
|
|
|
|
* -1
|
|
|
|
* ball.radius
|
|
|
|
* ball.radius
|
|
|
|
* ShotSetup.SHOT_OFFSET_Z_FACTOR
|
|
|
|
)
|
|
|
|
)
|
2025-01-07 18:59:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _process(_delta: float) -> void:
|
|
|
|
if Input.is_action_just_pressed("debug_1"):
|
2025-01-08 22:28:16 +00:00
|
|
|
spawn_balls(RAMP_SPAWN_GROUP)
|
|
|
|
if Input.is_action_just_pressed("debug_2"):
|
|
|
|
spawn_balls(DROP_SPAWN_GROUP)
|
|
|
|
if Input.is_action_just_pressed("debug_3"):
|
|
|
|
spawn_balls(PUTT_SPAWN_GROUP, PUTT_VEC)
|