LevelStreaming eingerichtet
This commit is contained in:
parent
160c62d98f
commit
d024f40aa7
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Content/Levels/PersistentLevel.umap
Normal file
BIN
Content/Levels/PersistentLevel.umap
Normal file
Binary file not shown.
BIN
Content/Levels/PersistentLevel_BuiltData.uasset
Normal file
BIN
Content/Levels/PersistentLevel_BuiltData.uasset
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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<UAudioComponent>(); //<> 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<UAudioComponent>(); //<> 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<AActor*> OverlapingActors;
|
||||
//find All Overlapping Actors
|
||||
TArray<AActor*> 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<UPrimitiveComponent>()->GetMass();
|
||||
UE_LOG(LogTemp, Warning, TEXT("%s is on the pressureplate"), *Actor->GetName());
|
||||
}
|
||||
//Add Up Their Masses
|
||||
for (AActor* Actor : OverlapingActors)
|
||||
{
|
||||
TotalMass += Actor->FindComponentByClass<UPrimitiveComponent>()->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);
|
||||
// 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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<AActor*> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user