Godot Version
4.5
So basically I want to instantiate a new rigidbody2d as I am making a tool where I can mess around with physics and i noticed that it doesnt load the soundstream on the cloned balls
This script is what instantiates the ball
extends Node2D
@onready var physBall = $physBall
@onready var physBallLbl = $physBallLbl
func _on_spawn_btn_pressed() -> void:
GlobalCounter.physBalls += 1
var physBallScn = preload("res://Scenes/physBall.tscn")
var newPhysBallScn = physBallScn.instantiate()
add_child(newPhysBallScn)
newPhysBallScn.position = Vector2(512.0, 184.0)
newPhysBallScn.name = "physBall"
physBallLbl.text = "PhysBalls: " + str(GlobalCounter.physBalls)
This is the code for when my ball hits an object (which its supposed to play a sound)
func _on_body_entered(_body: Node) -> void:
# When node hits an object
var randSfx = randi_range(1, 3)
var basketBallStream = load("res://Assets/Audio/SFX/basketball" + str(randSfx) + ".mp3")
impactPlayer.stream = basketBallStream
impactPlayer.play()
