Dancing in and out of the triggervolume would trigger the doorsound regardless of the door being half way open/close… Makes no sense, so I put in a check for CurrentYaw vs InitialYaw
On OpenDoor i put +5.f since the door would start to move before reaching the play sound in the code and it would no longer be at exactly InitialYaw
On CloseDoor i put everything in the initial yaw vs current yaw check, so you can’t play the open door sound unless the closedoor sound has been played… Gives a nice feel to the doorsound
The way you can make it play one right after the other if you activate dooropen right when it closes
void UOpenDoor::OpenDoor(float DeltaTime)
{
CurrentYaw = FMath::FInterpConstantTo(CurrentYaw, OpenAngle, DeltaTime, DoorOpenSpeed);
FRotator DoorRotation = GetOwner()->GetActorRotation();
DoorRotation.Yaw = CurrentYaw;
GetOwner()->SetActorRotation(DoorRotation);
if (!AudioComponent) { return; }
if (!OpenDoorSound)
{
OpenDoorSound = true;
CloseDoorSound = false;
if (CurrentYaw < InitialYaw+5.f)
{
AudioComponent->Play();
}
}
}
void UOpenDoor::CloseDoor(float DeltaTime)
{
CurrentYaw = FMath::FInterpConstantTo(CurrentYaw, InitialYaw, DeltaTime, DoorCloseSpeed);
FRotator DoorRotation = GetOwner()->GetActorRotation();
DoorRotation.Yaw = CurrentYaw;
GetOwner()->SetActorRotation(DoorRotation);
if (!AudioComponent) { return; }
if (CurrentYaw == InitialYaw)
{
if (!CloseDoorSound)
{
AudioComponent->Play();
CloseDoorSound = true;
OpenDoorSound = false;
}
}
}