diff --git a/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/SparksV2_2_Blueprint.uasset b/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/SparksV2_2_Blueprint.uasset new file mode 100644 index 0000000..0b9171e Binary files /dev/null and b/Content/EVERYTHINGPROGRAMMINGRELATED/Blueprints/SparksV2_2_Blueprint.uasset differ diff --git a/Content/Levels/FactoryHall.umap b/Content/Levels/FactoryHall.umap index cf186ed..8110da8 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 7f186b4..24b4811 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 new file mode 100644 index 0000000..ec76cd8 Binary files /dev/null and b/Content/Levels/PersistentLevel.umap differ diff --git a/Content/Levels/PersistentLevel_BuiltData.uasset b/Content/Levels/PersistentLevel_BuiltData.uasset new file mode 100644 index 0000000..8471d10 Binary files /dev/null and b/Content/Levels/PersistentLevel_BuiltData.uasset differ diff --git a/Content/Levels/Raum4.umap b/Content/Levels/Raum4.umap index 34e727d..de28b32 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 3c9b767..30bb942 100644 Binary files a/Content/Levels/Raum4_BuiltData.uasset and b/Content/Levels/Raum4_BuiltData.uasset differ diff --git a/Content/Levels/Untitled.umap b/Content/Levels/Untitled.umap index 2913f7d..327486f 100644 Binary files a/Content/Levels/Untitled.umap and b/Content/Levels/Untitled.umap differ diff --git a/Content/Levels/Untitled_BuiltData.uasset b/Content/Levels/Untitled_BuiltData.uasset index f2053a0..84cca85 100644 Binary files a/Content/Levels/Untitled_BuiltData.uasset and b/Content/Levels/Untitled_BuiltData.uasset differ diff --git a/Content/Levels/VillaDesign.umap b/Content/Levels/VillaDesign.umap index 48b1b8b..8ad8c5d 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 faae1db..e2aad91 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 d472e09..9e993fc 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 69514a3..45098e3 100644 Binary files a/Content/Levels/pipeMaze_BuiltData.uasset and b/Content/Levels/pipeMaze_BuiltData.uasset differ diff --git a/Source/BuildingEscape/OpenDoor.cpp b/Source/BuildingEscape/OpenDoor.cpp index 970a4e2..890b6ad 100644 --- a/Source/BuildingEscape/OpenDoor.cpp +++ b/Source/BuildingEscape/OpenDoor.cpp @@ -11,148 +11,168 @@ // Sets default values for this component's properties UOpenDoor::UOpenDoor() { - // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features - // off to improve performance if you don't need them. - PrimaryComponentTick.bCanEverTick = true; + // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features + // off to improve performance if you don't need them. + PrimaryComponentTick.bCanEverTick = true; - // ... + // ... } // Called when the game starts void UOpenDoor::BeginPlay() { - Super::BeginPlay(); + Super::BeginPlay(); - InitialYaw = GetOwner()->GetActorRotation().Yaw; - CurrentYaw = InitialYaw; - TargetAngleOfOpenDoor += InitialYaw; - - FindPressurePlateComponent(); + InitialYaw = GetOwner()->GetActorRotation().Yaw; + CurrentYaw = InitialYaw; + TargetAngleOfOpenDoor += InitialYaw; - FindAudioComponent(); - //ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn(); + 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()); - } + 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()); - } + if (!PressurePlate) + { + UE_LOG(LogTemp, Error, TEXT("%s has OpenDoor on it, but no PressurePlate set!"), *GetOwner()->GetName()); + } } // Called every frame void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { - Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); - // ... - //if(PressurePlate->IsOverlappingActor(ActorThatOpens)) // kann nullpointer + UE4 crash geben - //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); - //DoorLastOpened When the door was opened - DoorLastOpened = GetWorld()->GetTimeSeconds(); - } + // ... + //if(PressurePlate->IsOverlappingActor(ActorThatOpens)) // kann nullpointer + UE4 crash geben + //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); + //DoorLastOpened When the door was opened + DoorLastOpened = GetWorld()->GetTimeSeconds(); + } - else - { - //if door has been open longer than DoorCloseDelay - //if(GetWorld()->GetTimeSeconds() > DoorLastOpened + DoorDelay) - if(GetWorld()->GetTimeSeconds() - DoorLastOpened > DoorDelay) - CloseDoor(DeltaTime); - } + else + { + //if door has been open longer than DoorCloseDelay + //if(GetWorld()->GetTimeSeconds() > DoorLastOpened + DoorDelay) + if (GetWorld()->GetTimeSeconds() - DoorLastOpened > DoorDelay) + CloseDoor(DeltaTime); + } + + 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) { - FRotator DoorRotation = GetOwner()->GetActorRotation(); - //CurrentYaw = FMath::FInterpTo(CurrentYaw, TargetYaw, DeltaTime, 2.f); - CurrentYaw = FMath::Lerp(CurrentYaw, TargetAngleOfOpenDoor, DeltaTime * OpenDoorRotationSpeed); //complex Interpolation - DoorRotation.Yaw = CurrentYaw; - GetOwner()->SetActorRotation(DoorRotation); + 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; - } + CloseDoorSoundHasBeenPlayed = false; + if (!AudioComponent) { return; } + if (!OpenDoorSoundHasBeenPlayed) + { + AudioComponent->Play(); + OpenDoorSoundHasBeenPlayed = true; + } } void UOpenDoor::CloseDoor(float DeltaTime) { - FRotator DoorRotation = GetOwner()->GetActorRotation(); - CurrentYaw = FMath::Lerp(CurrentYaw, InitialYaw, DeltaTime * CloseDoorRotationSpeed); - DoorRotation.Yaw = CurrentYaw; - GetOwner()->SetActorRotation(DoorRotation); - - OpenDoorSoundHasBeenPlayed = false; - if(!AudioComponent){return;} - if(!CloseDoorSoundHasBeenPlayed) - { - AudioComponent->Play(); - CloseDoorSoundHasBeenPlayed = true; - } + 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; + } } +void UOpenDoor::rotateDoor(FRotator targetRotation) +{ + this->targetRotation = targetRotation; + rotating = true; +} + + float UOpenDoor::TotalMass() const { - float TotalMass = 0.f; + float TotalMass = 0.f; - //find All Overlapping Actors - TArray OverlapingActors; + //find All Overlapping Actors + TArray OverlapingActors; - if (!PressurePlate){return TotalMass;} - PressurePlate->GetOverlappingActors(OUT OverlapingActors); + if (!PressurePlate) { return TotalMass; } + PressurePlate->GetOverlappingActors(OUT OverlapingActors); - //Add Up Their Masses - for(AActor* Actor : OverlapingActors) - { - TotalMass += Actor -> FindComponentByClass()->GetMass(); - UE_LOG(LogTemp, Warning, TEXT("%s is on the pressureplate"), *Actor->GetName()); - } + //Add Up Their Masses + for (AActor* Actor : OverlapingActors) + { + TotalMass += Actor->FindComponentByClass()->GetMass(); + } - return TotalMass; + 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); +//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; +// FRotator CurrentRotation = GetOwner()->GetActorRotation(); +// FMath::Lerp(CurrentRotation, FRotator(0.f,90.f,0.f), 0.2f); - //GetOwner()->SetActorRotation(CurrentRotation); \ No newline at end of file +// 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); diff --git a/Source/BuildingEscape/OpenDoor.h b/Source/BuildingEscape/OpenDoor.h index ff725ed..5f349f7 100644 --- a/Source/BuildingEscape/OpenDoor.h +++ b/Source/BuildingEscape/OpenDoor.h @@ -1,5 +1,3 @@ -// Fill out your copyright notice in the Description page of Project Settings. - #pragma once #include "CoreMinimal.h" @@ -23,7 +21,6 @@ public: protected: // Called when the game starts virtual void BeginPlay() override; - public: // Called every frame virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; @@ -43,6 +40,10 @@ private: float CurrentYaw; float DoorLastOpened = 0.f; bool HasSoundBeenPlayed = false; + bool rotating = false; + FRotator targetRotation; + + void rotateDoor(FRotator targetRotation); UPROPERTY(EditAnywhere) float MassToOpenDoor = 50.f; @@ -62,9 +63,6 @@ private: UPROPERTY(EditAnywhere) ATriggerVolume* PressurePlate = nullptr; - UPROPERTY(EditAnywhere) - AActor* ActorThatOpens = nullptr; - UPROPERTY() UAudioComponent* AudioComponent = nullptr; diff --git a/Source/BuildingEscape/TriggerOpenDoor.cpp b/Source/BuildingEscape/TriggerOpenDoor.cpp index b701972..f4a8337 100644 --- a/Source/BuildingEscape/TriggerOpenDoor.cpp +++ b/Source/BuildingEscape/TriggerOpenDoor.cpp @@ -1,6 +1,5 @@ #include "TriggerOpenDoor.h" - UTriggerOpenDoor::UTriggerOpenDoor() { PrimaryComponentTick.bCanEverTick = true; @@ -14,6 +13,10 @@ void UTriggerOpenDoor::BeginPlay() { 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()); + } } @@ -23,13 +26,17 @@ void UTriggerOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, Super::TickComponent(DeltaTime, TickType, ThisTickFunction); if (!doorOpen) { + if(!TriggerVolume) + { + return; + } + TArray overlappingActors; - TriggerVolume->GetOverlappingActors(overlappingActors); if (overlappingActors.Num() >= 1) { - if (AudioComponent != nullptr) + if (AudioComponent) { AudioComponent->Play(); } @@ -42,12 +49,11 @@ void UTriggerOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, { if (GetOwner()->GetActorRotation().Equals(TargetRotation, 1.0)) { - UE_LOG(LogTemp, Display, TEXT("Target Rotation reached")) opening = false; } else { - GetOwner()->AddActorLocalRotation(TargetSpeed); + GetOwner()->AddActorLocalRotation(DeltaTime * TargetSpeed); } } } diff --git a/Source/BuildingEscape/TriggerOpenDoor.h b/Source/BuildingEscape/TriggerOpenDoor.h index ea88ec0..926d4b1 100644 --- a/Source/BuildingEscape/TriggerOpenDoor.h +++ b/Source/BuildingEscape/TriggerOpenDoor.h @@ -21,10 +21,10 @@ public: FActorComponentTickFunction* ThisTickFunction) override; UPROPERTY(EditAnywhere) - FRotator TargetRotation = FRotator(90.0f, 0.0f, 0.0f); + FRotator TargetRotation = FRotator(00.0f, 90.0f, 0.0f); UPROPERTY(EditAnywhere) - FRotator TargetSpeed = FRotator(1.0f, 0.0f, 0.0f); + FRotator TargetSpeed = FRotator(0.0f, 1.0f, 0.0f); UPROPERTY(EditAnywhere) ATriggerVolume * TriggerVolume = nullptr;