0 votes

I have a scene that has turrets that fire at the player and uses the audiostreamplayer2d to attenuate the volume depending on how far the player is from the turret. This scene works fine. I'll call this scene A.

I want this scene to be instanced into another scene (one that skins the tileset, adds minimap, adds HUD etc.) I'll call this scene B. Everything about scene B functions except the audiostreamplayer2d does not play at all. There are other regular audiostreamplayer (non-positional) that work fine in scene B (instanced from scene A).

Is there some information about the player position that scene B is not receiving from scene A?

I'll put the full script for scene B below, but the majority of it has to do with the minimap. My thinking was that
func ready():
level = load("res://scenes/levels/crust/Level3
8x816256.tscn").instance()
was all the code that godot needed to bring everything over from scene A. Any help is appreciated!

extends Node2D

const CAMERA_ZOOM = 1

var level = null
var mm = null

func ready():
level = load("res://scenes/levels/crust/Level3
8x816256.tscn").instance()
mm = level.getnode("Minimap")
level.remove
child(mm)
$MinimapContainer/MinimapViewport.addchild(mm)
mm.flip
v = true
mm.position = Vector2.ZERO
level.name = "Level"
$WorldContainer/WorldViewport.addchild(level)
$MinimapContainer/MinimapViewport/Camera2D.zoom = Vector2(CAMERA
ZOOM, CAMERAZOOM)
var prng = RandomNumberGenerator.new()
for n in level.get
children():
var tm = n.getnode("TileMap")
if tm != null and tm is TileMap:
tm.scale = Vector2(1, 1)
tm.cell
size = Vector2(64, 64)
tm.tileset = load("res://sprites/TileSets/CrustTiles.tres")
for x in range(32):
for y in range(32):
var fx = tm.is
cellxflipped(x, y)
var fy = tm.iscellyflipped(x, y)
var ft = tm.is
celltransposed(x, y)
var ix = tm.get
cell(x, y)
var variations = []
if ix == 12:
variations = [ 12, 40 ]
var variations2 = [ 12, 40, 41 ]
if (tm.getcell(x + 1, y) in variations2 and tm.getcell(x - 1, y) in variations2 and tm.getcell(x, y - 1) in variations2 and tm.getcell(x, y + 1) in variations2):
variations = [ 41 ]
fx = false
fy = false
ft = false
elif ix == 13:
variations = [ 13, 39 ]
elif ix == 15:
variations = [ 15, 38 ]
elif ix == 16:
variations = [ 16, 37 ]
elif ix == 17:
variations = [ 17, 33 ]
elif ix == 18:
variations = [ 18, 32 ]
elif ix == 21:
variations = [ 21, 36 ]
elif ix == 23:
variations = [ 23, 34 ]
elif ix == 24:
variations = [ 24, 35 ]
else:
variations = [ ix ]
tm.set_cell(x, y, variations[prng.randi() % variations.size()], fx, fy, ft)
update()
pass

func process(delta):
var player = level.getnode("Player")
assert(player != null)
$WorldContainer.get
material().setshaderparam("reversing", Input.isactionpressed("TimeReverse") and player.timereversalleft > 0)
$MinimapContainer.set
position(Vector2(getviewportrect().size.x - $MinimapContainer.getrect().size.x / 2 - 16, 16))
# If this fails, it means you didn't put the player in the level you specified
var pos = ((level.get
node("Player").getglobalposition() / 32) - (mm.texture.getsize() / 2))
$MinimapContainer/MinimapViewport/Camera2D.position = pos
$HUD/CoinLabel.text = str(player.coins)
$HUD/KeyLabel.text = str(player.keys)
$HUD/TimeReversalBar.set
size(Vector2(player.timereversalleft * 1820 / player.MAXTIMEREVERSAL, 40))
pass

in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.