public override void _Ready() { _audioNode = GetNode <AudioStreamPlayer3D>("Audio_Stream_Player"); _audioNode.Connect("finished", this, nameof(SoundFinished)); _audioNode.Stop(); _globals = GetNode <Globals>("/root/Globals"); }
private void SoundFinished() { if (ShouldLoop) { _audioNode.Play(); return; } var audioIndex = _globals.CreatedAudio.FirstOrDefault(a => a == this); if (audioIndex != null) { _globals.CreatedAudio.Remove(this); } _audioNode.Stop(); QueueFree(); }
// Called when the node enters the scene tree for the first time. public override void _Ready() { // Audio resources _audioPistolShot = ResourceLoader.Load <AudioStream>("res://assets/audio/sounds/weapons/gun_revolver_pistol_shot_04.wav"); _audioGunCock = ResourceLoader.Load <AudioStream>("res://assets/audio/sounds/weapons/GUN_MP5K_Cocked_Full_Action_02.wav"); _audioRifleShot = ResourceLoader.Load <AudioStream>("res://assets/audio/sounds/weapons/gun_rifle_sniper_shot_01.wav"); _explosionSound = ResourceLoader.Load <AudioStream>("res://assets/audio/sounds/weapons/explosion_large_no_tail_03.wav"); // Nodes _audioNodeGlobal = GetNode <AudioStreamPlayer>("Audio_Stream_Player"); _audioNodeLocal = GetNode <AudioStreamPlayer3D>("Audio_Stream_Player_3D"); _globals = GetNode <Globals>("/root/Globals"); // Setup _audioNodeGlobal.Connect("finished", this, "DestroySelfGlobal"); _audioNodeGlobal.Stop(); _audioNodeGlobal.MixTarget = AudioStreamPlayer.MixTargetEnum.Surround; _audioNodeLocal.Connect("finished", this, "DestroySelf3D"); _audioNodeLocal.Stop(); _audioNodeLocal.AttenuationFilterDb = -0.1f; _audioNodeLocal.MaxDb = 50; _audioNodeLocal.AttenuationFilterCutoffHz = 10000; // Attributes _shouldLoop = false; _globals = GetNode <Globals>("/root/Globals"); }
public override void _PhysicsProcess(float delta) { // if the tank respawns in the air or underground, bring it back to earth (issue #20) if (Transform.origin.y != originalY) { MoveAndSlide(new Vector3(0, originalY - Transform.origin.y, 0), new Vector3(0, 1, 0), true); } direction = new Vector3(0, 0, 0); rotrad = 0; float TurretRot = 0; bool change = false; if (IsNetworkMaster() && localcontrolactive) { if (Input.IsActionPressed("ui_left")) { rotrad += rotspeed * delta; //Rotate(Vector3.Left, Mathf.Pi); change = true; } // repeat for other directions if (Input.IsActionPressed("ui_right")) { rotrad -= rotspeed * delta; //Rotate(Vector3.Right, Mathf.Pi); change = true; } if (Input.IsActionPressed("ui_up")) { //direction = new Vector3((float) Math.Cos(rotation.y), 0, (float) Math.Sin(rotation.y)); //vel = new Vector3(0, 1, 0).Rotated(new Vector3(0,0,1), rotrad * Mathf.Pi) * speed * delta; direction = GetTransform().basis.z; change = true; } if (Input.IsActionPressed("ui_down")) { direction = -1 * GetTransform().basis.z; change = true; } if (Input.IsActionPressed("tur_left")) { TurretRot = rotspeed * delta; change = true; } if (Input.IsActionPressed("tur_right")) { TurretRot = -1 * rotspeed * delta; change = true; } // Only true on frame that key was pressed if (Input.IsActionJustPressed("ui_select")) { Rpc("NetFire"); Fire(); } if (Input.IsActionJustPressed("swapcam")) { SwapCamera(); } } direction = direction.Normalized(); direction = direction * speed * delta; //SetRotation(rotation); /* * To move in a direction based on rotation - * - y (up/down) of the vector must be 0 * - z is backward forward * - x is left right * new Vector2((float)Math.Cos(radians), (float)Math.Sin(radians)) * ^ inadequate * https://docs.godotengine.org/en/3.0/tutorials/3d/using_transforms.html */ //LinearVelocity = Transform.basis.z * speed; /* * Velocity measures the change in position per unit of time. * The new position is found by adding velocity to the previous position. */ if (change) { // play movement audio if (!trackmovementsound.IsPlaying()) { trackmovementsound.Play(); } //LocSetPosAndRot(direction, rotrad, deg2rad(yaw), deg2rad(pitch)); LocSetPosAndRot(direction, rotrad, TurretRot); // announce movement RpcUnreliable("NetSetTransforms", this.Transform, turret.Transform); } else { trackmovementsound.Stop(); } // we don't need this, cause out of scope after, but I like being explicit for sanity, blame biomed change = false; }
public void DestroySelf3D() { _audioNodeLocal.Stop(); QueueFree(); }