This commit is contained in:
Johannes Theiner 2021-03-13 19:26:55 +01:00
parent dcad52193e
commit 1f63391354
Signed by: joethei
GPG Key ID: 9D2B9A00FDA85BCD
13 changed files with 150 additions and 4 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,95 @@
#include "ExtraSpecialRotatingDoor.h"
#include "Components/AudioComponent.h"
#include "Kismet/GameplayStatics.h"
#include "Engine/World.h"
#include "Engine/Public/TimerManager.h"
UExtraSpecialRotatingDoor::UExtraSpecialRotatingDoor()
{
PrimaryComponentTick.bCanEverTick = true;
}
void UExtraSpecialRotatingDoor::BeginPlay()
{
Super::BeginPlay();
}
void UExtraSpecialRotatingDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
if (rotating)
{
FRotator Rotation = GetOwner()->GetActorRotation();
if (Rotation.Equals(targetRotation, 1.0f))
{
rotating = false;
}
else
{
Rotation.Add(DeltaTime * RotationSpeed * tempPitchRotation, 0.0f, DeltaTime * RotationSpeed * tempRollRotation);
GetOwner()->SetActorRotation(Rotation);
}
}
}
void UExtraSpecialRotatingDoor::Rotate(const FRotator TargetRotation)
{
FTimerHandle handle;
if(RotationDelay == 0)
{
Move(TargetRotation);
}else
{
GetWorld()->GetTimerManager().SetTimer(handle, [this, TargetRotation]() {
Move(TargetRotation);
}, RotationDelay, 1);
}
}
void UExtraSpecialRotatingDoor::Rotate()
{
FRotator rotation = GetOwner()->GetActorRotation();
rotation.Pitch = TargetAnglePitch;
rotation.Roll = TargetAngleRoll;
Rotate(rotation);
}
void UExtraSpecialRotatingDoor::Move(const FRotator TargetRotation)
{
this->targetRotation = TargetRotation;
rotating = true;
tempPitchRotation = (TargetRotation.Pitch < 0) ? -1.f : 1.f;
if (Negative)
{
tempPitchRotation = (TargetRotation.Pitch < 0) ? 1.f : -1.f;
}
tempRollRotation = (TargetRotation.Roll < 0) ? -1.f : 1.f;
if (Negative)
{
tempRollRotation = (TargetRotation.Roll < 0) ? 1.f : -1.f;
}
TArray<UAudioComponent*> Audios;
GetOwner()->GetComponents<UAudioComponent>(Audios);
if (Audios.Num() == 0) return;
if (soundHasBeenPlayed) return;
for (auto Audio : Audios)
{
if (Audio->ComponentHasTag("location"))
{
UGameplayStatics::PlaySoundAtLocation(GetOwner(), Audio->Sound, GetOwner()->GetActorLocation(),
GetOwner()->GetActorRotation(), 1, 1, 0,
Audio->AttenuationSettings, nullptr, GetOwner());
}
else
{
Audio->Play();
}
}
soundHasBeenPlayed = true;
}

View File

@ -0,0 +1,54 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "ExtraSpecialRotatingDoor.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDINGESCAPE_API UExtraSpecialRotatingDoor : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UExtraSpecialRotatingDoor();
protected:
virtual void BeginPlay() override;
void Rotate(FRotator TargetRotation);
UFUNCTION(BlueprintCallable)
void Rotate();
public:
virtual void TickComponent(float DeltaTime, ELevelTick TickType,
FActorComponentTickFunction* ThisTickFunction) override;
UPROPERTY(EditAnywhere)
float TargetAnglePitch = 90.0f;
UPROPERTY(EditAnywhere)
float TargetAngleRoll = 90.0f;
UPROPERTY(EditAnywhere)
float RotationSpeed = 15.f;
UPROPERTY(EditAnywhere)
float RotationDelay = 0.f;
UPROPERTY(EditAnywhere)
bool Negative = false;
private:
FRotator targetRotation;
bool rotating;
bool soundHasBeenPlayed;
float tempPitchRotation;
float tempRollRotation;
void Move(FRotator TargetRotation);
};

View File

@ -21,7 +21,7 @@ void URotatingActor::TickComponent(float DeltaTime, ELevelTick TickType, FActorC
if (rotating)
{
FRotator Rotation = GetOwner()->GetActorRotation();
if (Rotation.Equals(targetRotation, Tolerance))
if (Rotation.Equals(targetRotation, 1.0f))
{
rotating = false;
}

View File

@ -39,9 +39,6 @@ public:
UPROPERTY(EditAnywhere)
bool Negative = false;
UPROPERTY(EditAnywhere)
float Tolerance = 1.0f;
private:
FRotator targetRotation;
bool rotating;