2020-12-03 14:12:54 +01:00
|
|
|
#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
|
|
|
|
{
|
2020-12-08 12:21:49 +01:00
|
|
|
GetOwner()->AddActorLocalRotation(DeltaTime * RotationSpeed * FRotator(0.0f, tempRotation, 0.0f));
|
2020-12-03 14:12:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-08 12:21:49 +01:00
|
|
|
void URotatingActor::Rotate(const FRotator TargetRotation)
|
2020-12-03 14:12:54 +01:00
|
|
|
{
|
2020-12-08 12:21:49 +01:00
|
|
|
this->targetRotation = TargetRotation;
|
2020-12-03 14:12:54 +01:00
|
|
|
rotating = true;
|
2020-12-08 12:21:49 +01:00
|
|
|
tempRotation = (TargetRotation.Yaw < 0) ? -1.f : 1.f;
|
|
|
|
if(Negative)
|
|
|
|
{
|
|
|
|
tempRotation = (TargetRotation.Yaw < 0) ? 1.f : -1.f;
|
|
|
|
}
|
|
|
|
|
2020-12-03 14:12:54 +01:00
|
|
|
if(AudioComponent != nullptr && !soundHasBeenPlayed)
|
|
|
|
{
|
|
|
|
AudioComponent->Play();
|
|
|
|
soundHasBeenPlayed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-08 12:21:49 +01:00
|
|
|
void URotatingActor::Rotate()
|
2020-12-03 14:12:54 +01:00
|
|
|
{
|
|
|
|
FRotator rotation = GetOwner()->GetActorRotation();
|
|
|
|
rotation.Yaw = TargetAngle;
|
2020-12-08 12:21:49 +01:00
|
|
|
Rotate(rotation);
|
2020-12-03 14:12:54 +01:00
|
|
|
|
|
|
|
}
|