Produktion_Digitaler_Medien/Source/BuildingEscape/RotatingActor.cpp

56 lines
1.2 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();
}
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-21 16:55:07 +01:00
UAudioComponent * Audio = GetOwner()->FindComponentByClass<UAudioComponent>();
if(Audio != nullptr && !soundHasBeenPlayed)
2020-12-03 14:12:54 +01:00
{
2020-12-21 16:55:07 +01:00
Audio->Play();
2020-12-03 14:12:54 +01:00
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
}