53 lines
1.1 KiB
C++
53 lines
1.1 KiB
C++
|
#include "RotatingActor.h"
|
||
|
|
||
|
|
||
|
URotatingActor::URotatingActor()
|
||
|
{
|
||
|
PrimaryComponentTick.bCanEverTick = true;
|
||
|
}
|
||
|
|
||
|
void URotatingActor::BeginPlay()
|
||
|
{
|
||
|
Super::BeginPlay();
|
||
|
AudioComponent = GetOwner()->FindComponentByClass<UAudioComponent>();
|
||
|
if (!AudioComponent)
|
||
|
{
|
||
|
UE_LOG(LogTemp, Error, TEXT("No audio component found on: %s !"), *GetOwner()->GetName());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void URotatingActor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
||
|
{
|
||
|
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||
|
if (rotating)
|
||
|
{
|
||
|
if (GetOwner()->GetActorRotation().Equals(targetRotation, 1.0f))
|
||
|
{
|
||
|
rotating = false;
|
||
|
}else
|
||
|
{
|
||
|
|
||
|
GetOwner()->AddActorLocalRotation(DeltaTime * RotationSpeed * FRotator(0.0f, 1.0f, 0.0f));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void URotatingActor::rotate(FRotator targetRotation)
|
||
|
{
|
||
|
this->targetRotation = targetRotation;
|
||
|
rotating = true;
|
||
|
if(AudioComponent != nullptr && !soundHasBeenPlayed)
|
||
|
{
|
||
|
AudioComponent->Play();
|
||
|
soundHasBeenPlayed = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void URotatingActor::rotate()
|
||
|
{
|
||
|
FRotator rotation = GetOwner()->GetActorRotation();
|
||
|
rotation.Yaw = TargetAngle;
|
||
|
rotate(rotation);
|
||
|
|
||
|
}
|