#include "TriggerOpenDoor.h" UTriggerOpenDoor::UTriggerOpenDoor() { PrimaryComponentTick.bCanEverTick = true; } void UTriggerOpenDoor::BeginPlay() { Super::BeginPlay(); AudioComponent = GetOwner()->FindComponentByClass(); if (!AudioComponent) { UE_LOG(LogTemp, Error, TEXT("No audio component found on: %s !"), *GetOwner()->GetName()); } if(!TriggerVolume) { UE_LOG(LogTemp, Error, TEXT("No trigger volume found on: %s !"), *GetOwner()->GetName()); } } void UTriggerOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); if (!doorOpen) { if(!TriggerVolume) { return; } TArray overlappingActors; TriggerVolume->GetOverlappingActors(overlappingActors); if (overlappingActors.Num() >= 1) { if (AudioComponent) { AudioComponent->Play(); } doorOpen = true; opening = true; currentRotation = GetOwner()->GetActorRotation(); } } if (opening) { if (GetOwner()->GetActorRotation().Equals(TargetRotation, 1.0)) { opening = false; } else { GetOwner()->AddActorLocalRotation(DeltaTime * TargetSpeed); } } }