Produktion_Digitaler_Medien/Source/BuildingEscape/RotatingActor.cpp

60 lines
1.3 KiB
C++
Raw Normal View History

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)
{
2020-12-16 19:25:26 +01:00
FRotator Rotation = GetOwner()->GetActorRotation();
if (Rotation.Equals(targetRotation, 1.0f))
2020-12-03 14:12:54 +01:00
{
rotating = false;
}else
{
2020-12-16 19:25:26 +01:00
Rotation.Add(0.0f, DeltaTime * RotationSpeed * tempRotation, 0.0f);
GetOwner()->SetActorRotation(Rotation);
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
}