diff --git a/BuildingEscape.uproject b/BuildingEscape.uproject index 1812cca..a517dc0 100644 --- a/BuildingEscape.uproject +++ b/BuildingEscape.uproject @@ -18,6 +18,24 @@ { "Name": "OculusVR", "Enabled": false + }, + { + "Name": "MeshEditor", + "Enabled": true + }, + { + "Name": "Shotgun", + "Enabled": true, + "SupportedTargetPlatforms": [ + "Win64" + ] } + ], + "TargetPlatforms": [ + "HTML5", + "LinuxNoEditor", + "MacNoEditor", + "WindowsNoEditor", + "AllDesktop" ] } \ No newline at end of file diff --git a/Config/DefaultEngine.ini b/Config/DefaultEngine.ini index 837f59a..3899953 100644 --- a/Config/DefaultEngine.ini +++ b/Config/DefaultEngine.ini @@ -60,3 +60,4 @@ InitialAverageFrameRate=0.016667 PhysXTreeRebuildRate=10 DefaultBroadphaseSettings=(bUseMBPOnClient=False,bUseMBPOnServer=False,MBPBounds=(Min=(X=0.000000,Y=0.000000,Z=0.000000),Max=(X=0.000000,Y=0.000000,Z=0.000000),IsValid=0),MBPNumSubdivs=2) + diff --git a/Content/Box_Brush2_StaticMesh.uasset b/Content/Box_Brush2_StaticMesh.uasset new file mode 100644 index 0000000..ec3db43 Binary files /dev/null and b/Content/Box_Brush2_StaticMesh.uasset differ diff --git a/Content/Box_Brush2_StaticMesh1.uasset b/Content/Box_Brush2_StaticMesh1.uasset new file mode 100644 index 0000000..4c122c7 Binary files /dev/null and b/Content/Box_Brush2_StaticMesh1.uasset differ diff --git a/Content/Box_Brush2_StaticMesh2.uasset b/Content/Box_Brush2_StaticMesh2.uasset new file mode 100644 index 0000000..fc07fda Binary files /dev/null and b/Content/Box_Brush2_StaticMesh2.uasset differ diff --git a/Content/Box_Brush2_StaticMesh3.uasset b/Content/Box_Brush2_StaticMesh3.uasset new file mode 100644 index 0000000..a24da6f Binary files /dev/null and b/Content/Box_Brush2_StaticMesh3.uasset differ diff --git a/Content/Box_Brush2_StaticMesh4.uasset b/Content/Box_Brush2_StaticMesh4.uasset new file mode 100644 index 0000000..aa2d95e Binary files /dev/null and b/Content/Box_Brush2_StaticMesh4.uasset differ diff --git a/Content/Box_Brush2_StaticMesh5.uasset b/Content/Box_Brush2_StaticMesh5.uasset new file mode 100644 index 0000000..cfcbfa5 Binary files /dev/null and b/Content/Box_Brush2_StaticMesh5.uasset differ diff --git a/Content/Box_Brush4_StaticMesh.uasset b/Content/Box_Brush4_StaticMesh.uasset new file mode 100644 index 0000000..11e6bc1 Binary files /dev/null and b/Content/Box_Brush4_StaticMesh.uasset differ diff --git a/Content/Box_Brush4_StaticMesh1.uasset b/Content/Box_Brush4_StaticMesh1.uasset new file mode 100644 index 0000000..00fa2c3 Binary files /dev/null and b/Content/Box_Brush4_StaticMesh1.uasset differ diff --git a/Content/Box_Brush4_StaticMesh2.uasset b/Content/Box_Brush4_StaticMesh2.uasset new file mode 100644 index 0000000..ed7e6af Binary files /dev/null and b/Content/Box_Brush4_StaticMesh2.uasset differ diff --git a/Content/Box_Brush5_StaticMesh.uasset b/Content/Box_Brush5_StaticMesh.uasset new file mode 100644 index 0000000..b5bb4a7 Binary files /dev/null and b/Content/Box_Brush5_StaticMesh.uasset differ diff --git a/Content/Box_Brush6_StaticMesh.uasset b/Content/Box_Brush6_StaticMesh.uasset new file mode 100644 index 0000000..a75f237 Binary files /dev/null and b/Content/Box_Brush6_StaticMesh.uasset differ diff --git a/Content/Box_Brush_StaticMesh.uasset b/Content/Box_Brush_StaticMesh.uasset new file mode 100644 index 0000000..8e89032 Binary files /dev/null and b/Content/Box_Brush_StaticMesh.uasset differ diff --git a/Content/Box_Brush_StaticMesh1.uasset b/Content/Box_Brush_StaticMesh1.uasset new file mode 100644 index 0000000..e84e098 Binary files /dev/null and b/Content/Box_Brush_StaticMesh1.uasset differ diff --git a/Content/Box_Brush_StaticMesh2.uasset b/Content/Box_Brush_StaticMesh2.uasset new file mode 100644 index 0000000..ac7d67c Binary files /dev/null and b/Content/Box_Brush_StaticMesh2.uasset differ diff --git a/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/ConditionalLight_BP.uasset b/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/ConditionalLight_BP.uasset index 8e70957..6017366 100644 Binary files a/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/ConditionalLight_BP.uasset and b/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/ConditionalLight_BP.uasset differ diff --git a/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/ConditionalText_BP.uasset b/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/ConditionalText_BP.uasset index 5e2745b..714b712 100644 Binary files a/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/ConditionalText_BP.uasset and b/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/ConditionalText_BP.uasset differ diff --git a/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/DoorButton_BP1.uasset b/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/DoorButton_BP1.uasset index e93d43c..3b998f8 100644 Binary files a/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/DoorButton_BP1.uasset and b/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/DoorButton_BP1.uasset differ diff --git a/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/KeyPadToDetroy_Actor.uasset b/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/KeyPadToDetroy_Actor.uasset index 9be4167..534b644 100644 Binary files a/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/KeyPadToDetroy_Actor.uasset and b/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/KeyPadToDetroy_Actor.uasset differ diff --git a/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/ObjectSpawnButtonCube_BP.uasset b/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/ObjectSpawnButtonCube_BP.uasset new file mode 100644 index 0000000..9421f00 Binary files /dev/null and b/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/ObjectSpawnButtonCube_BP.uasset differ diff --git a/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/ObjectSpawnButton_BP.uasset b/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/ObjectSpawnButton_BP.uasset index 7ab0f35..ac0d599 100644 Binary files a/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/ObjectSpawnButton_BP.uasset and b/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/ObjectSpawnButton_BP.uasset differ diff --git a/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/PhysicsObjectCube_BP.uasset b/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/PhysicsObjectCube_BP.uasset new file mode 100644 index 0000000..1a49567 Binary files /dev/null and b/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/PhysicsObjectCube_BP.uasset differ diff --git a/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/PhysicsObject_BP.uasset b/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/PhysicsObject_BP.uasset index 41726cf..e5fe2dd 100644 Binary files a/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/PhysicsObject_BP.uasset and b/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/PhysicsObject_BP.uasset differ diff --git a/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/SelfDestructMinWeight_BP.uasset b/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/SelfDestructMinWeight_BP.uasset index a3b19ab..670a5f2 100644 Binary files a/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/SelfDestructMinWeight_BP.uasset and b/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/SelfDestructMinWeight_BP.uasset differ diff --git a/Content/EVERYTHINGPROGRAMMINGRELATED/Widgets/KeyPad_UI.uasset b/Content/EVERYTHINGPROGRAMMINGRELATED/Widgets/KeyPad_UI.uasset index a6e971f..969129a 100644 Binary files a/Content/EVERYTHINGPROGRAMMINGRELATED/Widgets/KeyPad_UI.uasset and b/Content/EVERYTHINGPROGRAMMINGRELATED/Widgets/KeyPad_UI.uasset differ diff --git a/Content/Eingene3DSachen/WuerfelBox.uasset b/Content/Eingene3DSachen/WuerfelBox.uasset new file mode 100644 index 0000000..d603c43 Binary files /dev/null and b/Content/Eingene3DSachen/WuerfelBox.uasset differ diff --git a/Content/Levels/FactoryHall.umap b/Content/Levels/FactoryHall.umap index 8110da8..40a14d5 100644 Binary files a/Content/Levels/FactoryHall.umap and b/Content/Levels/FactoryHall.umap differ diff --git a/Content/Levels/FactoryHall_BuiltData.uasset b/Content/Levels/FactoryHall_BuiltData.uasset index 24b4811..a25aeaa 100644 Binary files a/Content/Levels/FactoryHall_BuiltData.uasset and b/Content/Levels/FactoryHall_BuiltData.uasset differ diff --git a/Content/Levels/PersistentLevel.umap b/Content/Levels/PersistentLevel.umap index ec76cd8..acc1cc6 100644 Binary files a/Content/Levels/PersistentLevel.umap and b/Content/Levels/PersistentLevel.umap differ diff --git a/Content/Levels/PersistentLevel_BuiltData.uasset b/Content/Levels/PersistentLevel_BuiltData.uasset index 8471d10..f4196cd 100644 Binary files a/Content/Levels/PersistentLevel_BuiltData.uasset and b/Content/Levels/PersistentLevel_BuiltData.uasset differ diff --git a/Content/Levels/Raum4.umap b/Content/Levels/Raum4.umap index de28b32..fb35e95 100644 Binary files a/Content/Levels/Raum4.umap and b/Content/Levels/Raum4.umap differ diff --git a/Content/Levels/Raum4_BuiltData.uasset b/Content/Levels/Raum4_BuiltData.uasset index 30bb942..2223c04 100644 Binary files a/Content/Levels/Raum4_BuiltData.uasset and b/Content/Levels/Raum4_BuiltData.uasset differ diff --git a/Content/Levels/TestLevelForMechanics.umap b/Content/Levels/TestLevelForMechanics.umap index 6d96b48..b27b33a 100644 Binary files a/Content/Levels/TestLevelForMechanics.umap and b/Content/Levels/TestLevelForMechanics.umap differ diff --git a/Content/Levels/TestLevelForMechanics_BuiltData.uasset b/Content/Levels/TestLevelForMechanics_BuiltData.uasset index b53e9c4..140bd7a 100644 Binary files a/Content/Levels/TestLevelForMechanics_BuiltData.uasset and b/Content/Levels/TestLevelForMechanics_BuiltData.uasset differ diff --git a/Content/Levels/VillaDesign.umap b/Content/Levels/VillaDesign.umap index 8ad8c5d..46a1430 100644 Binary files a/Content/Levels/VillaDesign.umap and b/Content/Levels/VillaDesign.umap differ diff --git a/Content/Levels/VillaDesign_BuiltData.uasset b/Content/Levels/VillaDesign_BuiltData.uasset index e2aad91..ca425b8 100644 Binary files a/Content/Levels/VillaDesign_BuiltData.uasset and b/Content/Levels/VillaDesign_BuiltData.uasset differ diff --git a/Content/Levels/pipeMaze.umap b/Content/Levels/pipeMaze.umap index 9e993fc..501895a 100644 Binary files a/Content/Levels/pipeMaze.umap and b/Content/Levels/pipeMaze.umap differ diff --git a/Content/Levels/pipeMaze_BuiltData.uasset b/Content/Levels/pipeMaze_BuiltData.uasset index 45098e3..5889f69 100644 Binary files a/Content/Levels/pipeMaze_BuiltData.uasset and b/Content/Levels/pipeMaze_BuiltData.uasset differ diff --git a/Content/Models/new.uasset b/Content/Models/new.uasset index 6612130..bbe511a 100644 Binary files a/Content/Models/new.uasset and b/Content/Models/new.uasset differ diff --git a/Content/ModularFantasyHouse/Meshes/SM_Wall_Stone_Slopped.uasset b/Content/ModularFantasyHouse/Meshes/SM_Wall_Stone_Slopped.uasset new file mode 100644 index 0000000..c3c775c Binary files /dev/null and b/Content/ModularFantasyHouse/Meshes/SM_Wall_Stone_Slopped.uasset differ diff --git a/Content/Spiral_Stair_Brush2_StaticMesh.uasset b/Content/Spiral_Stair_Brush2_StaticMesh.uasset new file mode 100644 index 0000000..f535384 Binary files /dev/null and b/Content/Spiral_Stair_Brush2_StaticMesh.uasset differ diff --git a/Content/placeholder_flatSocket.uasset b/Content/placeholder_flatSocket.uasset new file mode 100644 index 0000000..ceeca94 Binary files /dev/null and b/Content/placeholder_flatSocket.uasset differ diff --git a/Content/placeholder_halfCylinderShell.uasset b/Content/placeholder_halfCylinderShell.uasset new file mode 100644 index 0000000..eda5381 Binary files /dev/null and b/Content/placeholder_halfCylinderShell.uasset differ diff --git a/Source/BuildingEscape/OpenDoor.cpp b/Source/BuildingEscape/OpenDoor.cpp index 890b6ad..41a3858 100644 --- a/Source/BuildingEscape/OpenDoor.cpp +++ b/Source/BuildingEscape/OpenDoor.cpp @@ -1,6 +1,4 @@ -// Fill out your copyright notice in the Description page of Project Settings. #include "OpenDoor.h" -#include "Components/AudioComponent.h" #include "Components/PrimitiveComponent.h" #include "Engine/World.h" #include "GameFramework/Actor.h" @@ -22,32 +20,6 @@ UOpenDoor::UOpenDoor() void UOpenDoor::BeginPlay() { Super::BeginPlay(); - - InitialYaw = GetOwner()->GetActorRotation().Yaw; - CurrentYaw = InitialYaw; - TargetAngleOfOpenDoor += InitialYaw; - - FindPressurePlateComponent(); - - FindAudioComponent(); - //ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn(); -} - -void UOpenDoor::FindAudioComponent() -{ - AudioComponent = GetOwner()->FindComponentByClass(); //<> for function templates - if (!AudioComponent) // same as if(PhysicsHandle == nullptr) - { - UE_LOG(LogTemp, Error, TEXT("No Audio component found on: %s !"), *GetOwner()->GetName()); - } -} - -void UOpenDoor::FindPressurePlateComponent() -{ - if (!PressurePlate) - { - UE_LOG(LogTemp, Error, TEXT("%s has OpenDoor on it, but no PressurePlate set!"), *GetOwner()->GetName()); - } } // Called every frame @@ -60,76 +32,36 @@ void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorCompon //if(PressurePlate && PressurePlate->IsOverlappingActor(ActorThatOpens)) //prüft erst, ob es ein actor gibt if (TotalMass() >= MassToOpenDoor) { - UE_LOG(LogTemp, Warning, TEXT("TEST OPEN DOOR")); - OpenDoor(DeltaTime); + OpenDoor(); //DoorLastOpened When the door was opened - DoorLastOpened = GetWorld()->GetTimeSeconds(); + doorLastOpened = GetWorld()->GetTimeSeconds(); } - else + else if(open) { //if door has been open longer than DoorCloseDelay //if(GetWorld()->GetTimeSeconds() > DoorLastOpened + DoorDelay) - if (GetWorld()->GetTimeSeconds() - DoorLastOpened > DoorDelay) - CloseDoor(DeltaTime); + if (GetWorld()->GetTimeSeconds() - doorLastOpened > RotationDelay) + CloseDoor(); } - - if(rotating) - { - if (GetOwner()->GetActorRotation().Equals(targetRotation, 1.0)) - { - rotating = false; - } - else - { - GetOwner()->AddActorLocalRotation(DeltaTime * OpenDoorRotationSpeed * FRotator(0.0f, 1.0f, 0.0f)); - } - } - - } -void UOpenDoor::OpenDoor(float DeltaTime) +void UOpenDoor::OpenDoor() { - FRotator DoorRotation = GetOwner()->GetActorRotation(); - //CurrentYaw = FMath::FInterpTo(CurrentYaw, TargetYaw, DeltaTime, 2.f); - CurrentYaw = FMath::Lerp(CurrentYaw, TargetAngleOfOpenDoor, DeltaTime * OpenDoorRotationSpeed); - //complex Interpolation - DoorRotation.Yaw = CurrentYaw; - rotateDoor(DoorRotation); - - CloseDoorSoundHasBeenPlayed = false; - if (!AudioComponent) { return; } - if (!OpenDoorSoundHasBeenPlayed) - { - AudioComponent->Play(); - OpenDoorSoundHasBeenPlayed = true; - } + FRotator rotation = GetOwner()->GetActorRotation(); + rotation.Yaw = TargetAngle; + Rotate(rotation); + open = true; } -void UOpenDoor::CloseDoor(float DeltaTime) +void UOpenDoor::CloseDoor() { - FRotator DoorRotation = GetOwner()->GetActorRotation(); - CurrentYaw = FMath::Lerp(CurrentYaw, InitialYaw, DeltaTime * CloseDoorRotationSpeed); - DoorRotation.Yaw = CurrentYaw; - rotateDoor(DoorRotation); - - OpenDoorSoundHasBeenPlayed = false; - if (!AudioComponent) { return; } - if (!CloseDoorSoundHasBeenPlayed) - { - AudioComponent->Play(); - CloseDoorSoundHasBeenPlayed = true; - } + FRotator rotation = GetOwner()->GetActorRotation(); + rotation.Yaw = 0.0f; + Rotate(rotation); + open = false; } -void UOpenDoor::rotateDoor(FRotator targetRotation) -{ - this->targetRotation = targetRotation; - rotating = true; -} - - float UOpenDoor::TotalMass() const { float TotalMass = 0.f; @@ -147,32 +79,4 @@ float UOpenDoor::TotalMass() const } return TotalMass; -} - -//Notes -//UE_LOG(LogTemp, Warning, TEXT("%f"), TargetYaw); -// UE_LOG(LogTemp, Warning, TEXT("%s"), *GetOwner()->GetActorRotation().ToString()); -// UE_LOG(LogTemp, Warning, TEXT("The Yaw is: %f"), GetOwner()->GetActorRotation().Yaw); - -// FRotator CurrentRotation = GetOwner()->GetActorRotation(); -// FMath::Lerp(CurrentRotation, FRotator(0.f,90.f,0.f), 0.2f); - -// GetOwner()->SetActorRotation(CurrentRotation); -// UE_LOG(LogTemp, Warning, TEXT("The Yaw is: %f"), CurrentRotation.Yaw); -//TargetYaw = 90.f; -// FRotator OpenDoor(0.f, 0.f, 0.f); -// //OpenDoor.Yaw = FMath::Lerp(CurrentYaw, TargetYaw, 0.02f); //complex Interpolation -// OpenDoor.Yaw = FMath::FInterpTo(CurrentYaw, TargetYaw, DeltaTime, 2.f);//complex Interpolation Framerate unabhängig wegen Deltatime -// //OpenDoor.Yaw = FMath::FInterpConstantTo(CurrentYaw, TargetYaw, DeltaTime, 0.02f); //lineare interpolation -// GetOwner()->SetActorRotation(OpenDoor); - - -//float f = 10.f; -//FRotator CurrentRotation = GetOwner()->GetActorRotation(); -//FRotator Rotation = FRotator(0.f, -90.f, 0.f); -//FRotator OpenDoor={float,float,float} -//FRotator OpenDoor{float,float,float} -//FRotator OpenDoor(float,float,float) -//CurrentRotation.Yaw = 90.f; - -//GetOwner()->SetActorRotation(CurrentRotation); +} \ No newline at end of file diff --git a/Source/BuildingEscape/OpenDoor.h b/Source/BuildingEscape/OpenDoor.h index 5f349f7..07142be 100644 --- a/Source/BuildingEscape/OpenDoor.h +++ b/Source/BuildingEscape/OpenDoor.h @@ -1,6 +1,8 @@ #pragma once #include "CoreMinimal.h" + +#include "RotatingActor.h" #include "Components/AudioComponent.h" #include "Components/ActorComponent.h" #include "Engine/TriggerVolume.h" @@ -10,7 +12,7 @@ UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) -class BUILDINGESCAPE_API UOpenDoor : public UActorComponent +class BUILDINGESCAPE_API UOpenDoor : public URotatingActor { GENERATED_BODY() @@ -24,46 +26,19 @@ protected: public: // Called every frame virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; - void OpenDoor(float DeltaTime); - void CloseDoor(float DeltaTime); + void OpenDoor(); + void CloseDoor(); float TotalMass() const; - void FindAudioComponent(); - void FindPressurePlateComponent(); - //Tracks if Sound has been Played - bool OpenDoorSoundHasBeenPlayed = false; - bool CloseDoorSoundHasBeenPlayed = true; - private: - - float InitialYaw; - float CurrentYaw; - float DoorLastOpened = 0.f; - bool HasSoundBeenPlayed = false; - bool rotating = false; - FRotator targetRotation; - - void rotateDoor(FRotator targetRotation); + bool open = false; + float doorLastOpened; UPROPERTY(EditAnywhere) float MassToOpenDoor = 50.f; - UPROPERTY(EditAnywhere) - float TargetAngleOfOpenDoor =90.f; - - UPROPERTY(EditAnywhere) - float OpenDoorRotationSpeed = 2.f; - - UPROPERTY(EditAnywhere) - float CloseDoorRotationSpeed = 0.5f; - - UPROPERTY(EditAnywhere) - float DoorDelay = 2.f; //2 second delay - UPROPERTY(EditAnywhere) ATriggerVolume* PressurePlate = nullptr; - UPROPERTY() - UAudioComponent* AudioComponent = nullptr; }; diff --git a/Source/BuildingEscape/RotatingActor.cpp b/Source/BuildingEscape/RotatingActor.cpp new file mode 100644 index 0000000..154282c --- /dev/null +++ b/Source/BuildingEscape/RotatingActor.cpp @@ -0,0 +1,57 @@ +#include "RotatingActor.h" + + +URotatingActor::URotatingActor() +{ + PrimaryComponentTick.bCanEverTick = true; +} + +void URotatingActor::BeginPlay() +{ + Super::BeginPlay(); + AudioComponent = GetOwner()->FindComponentByClass(); + 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, tempRotation, 0.0f)); + } + } +} + +void URotatingActor::Rotate(const FRotator TargetRotation) +{ + this->targetRotation = TargetRotation; + rotating = true; + tempRotation = (TargetRotation.Yaw < 0) ? -1.f : 1.f; + if(Negative) + { + tempRotation = (TargetRotation.Yaw < 0) ? 1.f : -1.f; + } + + if(AudioComponent != nullptr && !soundHasBeenPlayed) + { + AudioComponent->Play(); + soundHasBeenPlayed = true; + } +} + +void URotatingActor::Rotate() +{ + FRotator rotation = GetOwner()->GetActorRotation(); + rotation.Yaw = TargetAngle; + Rotate(rotation); + +} diff --git a/Source/BuildingEscape/RotatingActor.h b/Source/BuildingEscape/RotatingActor.h new file mode 100644 index 0000000..ff0b0a4 --- /dev/null +++ b/Source/BuildingEscape/RotatingActor.h @@ -0,0 +1,51 @@ +#pragma once + +#include "CoreMinimal.h" +#include "GameFramework/Actor.h" +#include "Components/ActorComponent.h" +#include "Components/AudioComponent.h" + +#include "RotatingActor.generated.h" + + +UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +class BUILDINGESCAPE_API URotatingActor : public UActorComponent +{ + GENERATED_BODY() + +public: + URotatingActor(); + +protected: + virtual void BeginPlay() override; + + void Rotate(FRotator TargetRotation); + + UFUNCTION() + void Rotate(); + +public: + virtual void TickComponent(float DeltaTime, ELevelTick TickType, + FActorComponentTickFunction* ThisTickFunction) override; + + UPROPERTY(EditAnywhere) + float TargetAngle = 90.0f; + + UPROPERTY(EditAnywhere) + UAudioComponent * AudioComponent; + + UPROPERTY(EditAnywhere) + float RotationSpeed = 15.f; + + UPROPERTY(EditAnywhere) + float RotationDelay = 2.f; + + UPROPERTY(EditAnywhere) + bool Negative = false; + +private: + FRotator targetRotation; + bool rotating; + bool soundHasBeenPlayed; + float tempRotation; +}; diff --git a/Source/BuildingEscape/TriggerOpenDoor.cpp b/Source/BuildingEscape/TriggerOpenDoor.cpp index f4a8337..38d0f9e 100644 --- a/Source/BuildingEscape/TriggerOpenDoor.cpp +++ b/Source/BuildingEscape/TriggerOpenDoor.cpp @@ -8,11 +8,6 @@ UTriggerOpenDoor::UTriggerOpenDoor() void UTriggerOpenDoor::BeginPlay() { Super::BeginPlay(); - AudioComponent = GetOwner()->FindComponentByClass(); - if (!AudioComponent) - { - UE_LOG(LogTemp, Error, TEXT("No audio component found on: %s !"), *GetOwner()->GetName()); - } if(!TriggerVolume) { UE_LOG(LogTemp, Error, TEXT("No trigger volume found on: %s !"), *GetOwner()->GetName()); @@ -24,8 +19,7 @@ void UTriggerOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); - if (!doorOpen) - { + if(!TriggerVolume) { return; @@ -35,25 +29,6 @@ void UTriggerOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, TriggerVolume->GetOverlappingActors(overlappingActors); if (overlappingActors.Num() >= 1) { - - if (AudioComponent) - { - AudioComponent->Play(); - } - doorOpen = true; - opening = true; - currentRotation = GetOwner()->GetActorRotation(); + Rotate(); } - } - if (opening) - { - if (GetOwner()->GetActorRotation().Equals(TargetRotation, 1.0)) - { - opening = false; - } - else - { - GetOwner()->AddActorLocalRotation(DeltaTime * TargetSpeed); - } - } } diff --git a/Source/BuildingEscape/TriggerOpenDoor.h b/Source/BuildingEscape/TriggerOpenDoor.h index 926d4b1..72c0054 100644 --- a/Source/BuildingEscape/TriggerOpenDoor.h +++ b/Source/BuildingEscape/TriggerOpenDoor.h @@ -3,6 +3,8 @@ #pragma once #include "CoreMinimal.h" + +#include "RotatingActor.h" #include "Components/ActorComponent.h" #include "Components/AudioComponent.h" #include "Engine/TriggerVolume.h" @@ -11,7 +13,7 @@ UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) -class BUILDINGESCAPE_API UTriggerOpenDoor : public UActorComponent +class BUILDINGESCAPE_API UTriggerOpenDoor : public URotatingActor { GENERATED_BODY() @@ -19,24 +21,11 @@ public: UTriggerOpenDoor(); virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; - - UPROPERTY(EditAnywhere) - FRotator TargetRotation = FRotator(00.0f, 90.0f, 0.0f); - - UPROPERTY(EditAnywhere) - FRotator TargetSpeed = FRotator(0.0f, 1.0f, 0.0f); UPROPERTY(EditAnywhere) ATriggerVolume * TriggerVolume = nullptr; - UPROPERTY(EditAnywhere) - UAudioComponent * AudioComponent = nullptr; - protected: virtual void BeginPlay() override; - -private: - bool doorOpen = false; - bool opening = false; - FRotator currentRotation; + };