var _snd = audioStr.instantiate();
add_child(_snd);
You didn’t include a definition for audioStr, but I suspect that is a reference to AudioStreamPlayer. If that is the case, you don’t have any safeguard against creating multiple instances. When you are hearing two sounds, it may be because multiple players are running at the same time.
You are also playing the same sound in multiple states. The code that prints “here 2” does not prevent the other conditional from being evaluated, and if that is seen as true then the elevEnd sound will be played.
thanks
problem was i had 2 elevators in the level…
And they were both coming from the same y position -96.0 when the player entered the level…
and i was checking if playerPosition.y < -20, elevState = 3;
So the 2 elevators were both moving down and playing the sound when they reached the position…
ive already fixed it with rect2; problem was in elevState 2…
func is_player_in_elevator_zone() -> bool:
var rect = Rect2(-100, -200, 300, 400)
return rect.has_point(to_local(Player.global_position))
match elevState:
0:
offset.y = 0;
if ( callBtnsActive == true ):
elevState = 6;
if ( playerIN == true && Input.is_action_just_pressed("key_up") ):
elevState = 1;
Snd.playSnd(Snd.elevEnd);
1:
position = position.move_toward( MoveTo , speed * delta );
offset.y = fixFeetOffset;
2: # spawnToMoveDown
if is_player_in_elevator_zone():
Player.position = position + Vector2( 70, 31 );
elevState = 3;
else:
position = MoveToSpawn;
elevState = 0;
3:
position = position.move_toward( MoveToSpawn , speed * delta );
offset.y = -fixFeetOffset;
if ( position == MoveToSpawn ):
elevState = 0;
Snd.playSnd(Snd.elevEnd);
That is, check if the length of the distance between the two positions is within a really tiny distance from zero. It’s a good habit to get into; floating point uses sliding precision, and that can cause unexpected bugs.