My Level :)

I had so much fun making the Level! :slight_smile:
I tried doing some tricky things like creating components in the code instead of in the UE…etc.

OpenDoor.h

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "OpenDoor.generated.h"

class ATriggerVolume;

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class HORRORENGINE_API UOpenDoor : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UOpenDoor();

protected:
	// Called when the game starts
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
	// Open/Close Door
	void OpenDoor(float DeltaTime);
	void CloseDoor(float DeltaTime);
	void FindAudioComponent();
	void PlayDoorSound1();
	void PlayDoorSound2();
	// The Key
	AActor* GetStaticMesh();
	// ATriggerVolume
	UPROPERTY(EditAnywhere)
		ATriggerVolume* TriggerVolume = nullptr;
	UPROPERTY(EditAnywhere)
		FName LockName;


private:
	// Lock/Unlock
	float AnimateDoorUnlock(float DeltaTime);
	float AnimateDoorLock(float DeltaTime);
private:
	//Lerping (For DoorLock)
	float LockInitialYaw;
	float LockCurrentYaw;
	UPROPERTY(EditAnywhere)
		float LockTargetYaw = 90.f;
	UPROPERTY(EditAnywhere)
		float UnLock_Speed = 300.f;
	UPROPERTY(EditAnywhere)
		float Lock_Speed = 300.f;

	// For DoorLock
	bool b_IsNinety = false;
	bool b_IsZero = true;
	//Lerping (For Door)
	float InitialtYaw;
	float CurrentYaw;
	UPROPERTY(EditAnywhere)
		float TargetYaw = 90.f;
	UPROPERTY(EditAnywhere)
		float Open_Speed = 1.f;
	UPROPERTY(EditAnywhere)
		float Close_Speed = 1.f;
	// Find the LockDoor (Components)
	TArray<UStaticMeshComponent*> Components;
	TArray<UAudioComponent*> AudioComponents;

	//TimeSecconds
	float TimeSecconds = 0.f;

	//For Sound ( Door )
	bool b_SwitchBinary1;
	//For Sound ( DoorLock )
	bool b_SwitchBinary2;
	bool DoorSound1 = false;
	bool DoorSound2 = false;
};

OpenDoor.cpp

#include "OpenDoor.h"
#include "Engine/World.h"
#include "Engine/StaticMeshActor.h"
#include "GameFramework/Actor.h"
#include "Components/AudioComponent.h"
#include "Components/StaticMeshComponent.h"
#include "Engine/TriggerVolume.h"


// 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;
}
// Called when the game starts
void UOpenDoor::BeginPlay()
{	Super::BeginPlay();

	FindAudioComponent();
	InitialtYaw = GetOwner()->GetActorRotation().Yaw;
	CurrentYaw = InitialtYaw;
	TargetYaw += InitialtYaw;
	GetOwner()->GetComponents(Components);
	for (UStaticMeshComponent* StaticMeshComponent: Components)
	{
		if (StaticMeshComponent->ComponentHasTag("Lock"))
		{
			LockInitialYaw = StaticMeshComponent->GetRelativeRotation().Yaw;
			LockCurrentYaw = LockInitialYaw;
			LockTargetYaw += LockInitialYaw;
		}
	}

}
// Called every frame
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	if (TriggerVolume && GetStaticMesh() && GetStaticMesh()->ActorHasTag(LockName))
	{
		//UE_LOG(LogTemp, Warning, TEXT("%s"), *GetStaticMesh()->GetName()); //77
		if (!b_IsNinety)
		{
			AnimateDoorUnlock(DeltaTime);
			TimeSecconds = GetWorld()->GetTimeSeconds();
		}
		else
		{
			if (!b_IsZero)
			{
				AnimateDoorLock(DeltaTime);
				TimeSecconds = GetWorld()->GetTimeSeconds();
			}
			else
			{
				OpenDoor(DeltaTime);
				TimeSecconds = GetWorld()->GetTimeSeconds();
			}
		}
			//TimeSecconds = GetWorld()->GetTimeSeconds();
	}
	else
	{
		if ( (GetWorld()->GetTimeSeconds() - TimeSecconds) >= .5f )
		{
			//UE_LOG(LogTemp, Warning, TEXT("CloseDoor"));
			CloseDoor(DeltaTime);
		}
	}
}
void UOpenDoor::OpenDoor(float DeltaTime)
{
	//GetActorRotation
	FRotator GetActorRotation = GetOwner()->GetActorRotation();
	//Make Lerp
	CurrentYaw = FMath::FInterpTo(CurrentYaw, TargetYaw, DeltaTime, Open_Speed);
	//Set ActorRotation to CurrentYaw
	GetActorRotation.Yaw = CurrentYaw;
	GetOwner()->SetActorRotation(GetActorRotation);
}
void UOpenDoor::CloseDoor(float DeltaTime)
{
	if (CurrentYaw <= (InitialtYaw + 10.f))
	{
		DoorSound1 = false;
		DoorSound2 = false;
	}
	//GetActorRotation
	FRotator GetActorRotation = GetOwner()->GetActorRotation();
	//Make Lerp
	CurrentYaw = FMath::FInterpTo(CurrentYaw, InitialtYaw, DeltaTime, Open_Speed);
	//Set ActorRotation to CurrentYaw
	GetActorRotation.Yaw = CurrentYaw;
	GetOwner()->SetActorRotation(GetActorRotation);
	b_IsNinety = false;
	b_IsZero = true;
}
float UOpenDoor::AnimateDoorUnlock(float DeltaTime)
{
	if (!DoorSound1)
	{
		PlayDoorSound1();
	}
	//UE_LOG(LogTemp, Error, TEXT("%i"), Components.Num()); //77
	for (UStaticMeshComponent* StaticMeshComponent: Components)
	{
		if (StaticMeshComponent->ComponentHasTag("Lock"))
		{
			//Make Lerp
			FRotator GetActorRotation = StaticMeshComponent->GetRelativeRotation();
			LockCurrentYaw = FMath::FInterpConstantTo(LockCurrentYaw, LockTargetYaw, DeltaTime, UnLock_Speed);
			//Set ActorRotation to LockCurrentYaw
			GetActorRotation.Roll = 0.f;
			GetActorRotation.Pitch = 0.f;
			GetActorRotation.Yaw = LockCurrentYaw;
			StaticMeshComponent->SetRelativeRotation(GetActorRotation);
			b_IsZero = false;
			if (GetActorRotation.Yaw >= 90.f)
			{
				b_IsNinety = true;
				return GetActorRotation.Yaw;
			}
		}
	}
	return false;
}
float UOpenDoor::AnimateDoorLock(float DeltaTime)
{
	if (!DoorSound2)
	{
		PlayDoorSound2();
	}
	for (UStaticMeshComponent* StaticMeshComponent : Components)
	{
		if (StaticMeshComponent->ComponentHasTag("Lock"))
		{
			//Make Lerp
			FRotator GetActorRotation = StaticMeshComponent->GetRelativeRotation();
			LockCurrentYaw = FMath::FInterpConstantTo(LockCurrentYaw, LockInitialYaw, DeltaTime, Lock_Speed);
			//Set ActorRotation to LockCurrentYaw
			GetActorRotation.Roll = 0.f;
			GetActorRotation.Pitch = 0.f;
			GetActorRotation.Yaw = LockCurrentYaw;
			UE_LOG(LogTemp, Warning, TEXT("[Lock] GetActorRotation.Yaw: %s"), *GetActorRotation.ToString());
			StaticMeshComponent->SetRelativeRotation(GetActorRotation);
			if (GetActorRotation.Yaw <= 0.f)
			{
				b_IsZero = true;
				return GetActorRotation.Yaw;
			}
		}
	}
	return 0.f;
}
AActor* UOpenDoor::GetStaticMesh()
{
	TArray<AActor*> OverlappingActors{ nullptr };
	TriggerVolume->GetOverlappingActors(OverlappingActors);
	for (AActor* Actor : OverlappingActors)
	{
		if (Actor->ActorHasTag(LockName))
		{
			return Actor;
		}
		else
		{
			//UE_LOG(LogTemp, Error, TEXT("[GetTotalMass] (Key3) Not Found"));  //77
		}
	}
	AActor* nullptrActor = nullptr;
	return nullptrActor;
}

void UOpenDoor::FindAudioComponent()
{
	GetOwner()->GetComponents(AudioComponents);
	TArray<UAudioComponent*> TempAudioComponents;
	for (UAudioComponent* UAudioComponent : AudioComponents)
	{
		TempAudioComponents.Add(UAudioComponent);
	}
	AudioComponents.Empty();
	AudioComponents = TempAudioComponents;
	if (!AudioComponents.IsValidIndex(1))
	{
		UE_LOG(LogTemp, Error, TEXT("%s: MISSING Audio Component!"), *GetOwner()->GetName());
	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("AudioComponent Was Found"));
	}
}
void UOpenDoor::PlayDoorSound1()
{
	if (!AudioComponents.IsValidIndex(1) && !AudioComponents[0]) { return; }
	AudioComponents[0]->Play();
	DoorSound1 = true;
}
void UOpenDoor::PlayDoorSound2()
{
	if (!AudioComponents.IsValidIndex(1) && !AudioComponents[1]) { return; }
	AudioComponents[1]->Play();
	DoorSound2 = true;
}

OpenDoor2.h


#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "OpenDoor2.generated.h"

class ATriggerVolume;

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class HORRORENGINE_API UOpenDoor2 : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UOpenDoor2();

protected:
	// Called when the game starts
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
	// Open/Close Door
	void OpenDoor(float DeltaTime);
	void CloseDoor(float DeltaTime);
	// The Key
	AActor* GetStaticMesh();
	// ATriggerVolume
	UPROPERTY(EditAnywhere)
		ATriggerVolume* TriggerVolume = nullptr;


private:
	// Lock/Unlock
	float AnimateDoorUnlock(float DeltaTime);
	float AnimateDoorLock(float DeltaTime);
private:
	//Lerping (For Door)
	float InitialYaw;
	float CurrentYaw;
	UPROPERTY(EditAnywhere)
		float TargetYaw = 90.f;
	UPROPERTY(EditAnywhere)
		float Open_Speed = 1.f;
	UPROPERTY(EditAnywhere)
		float Close_Speed = 1.f;

	//Lerping (For DoorLock)
	float LockInitialZ;
	float LockCurrentZ;
	UPROPERTY(EditAnywhere)
		float LockTargetZ = 2.5f;
	UPROPERTY(EditAnywhere)
		float UnLock_Speed = 300.f;
	UPROPERTY(EditAnywhere)
		bool b_Lock = false;
	// For DoorLock
	bool b_Unlock = false;

	// Find the LockDoor (Components)
	TArray<UStaticMeshComponent*> Components;

	//TimeSecconds
	float TimeSecconds = 0.f;

	//For Sound ( Door )
	bool b_SwitchBinary1;
	//For Sound ( DoorLock )
	bool b_SwitchBinary2;		
};

OpenDoor2.cpp




#include "OpenDoor2.h"
#include "Engine/World.h"
#include "Engine/StaticMeshActor.h"
#include "GameFramework/Actor.h"
#include "Components/StaticMeshComponent.h"
#include "Engine/TriggerVolume.h"

// Sets default values for this component's properties
UOpenDoor2::UOpenDoor2()
{
	// 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 UOpenDoor2::BeginPlay()
{
	Super::BeginPlay();

	InitialYaw = GetOwner()->GetActorRotation().Yaw;
	CurrentYaw = InitialYaw;
	TargetYaw += InitialYaw;

	GetOwner()->GetComponents(Components);
	for (UStaticMeshComponent* StaticMeshComponent : Components)
	{
		if (StaticMeshComponent->ComponentHasTag("Lock"))
		{
			LockInitialZ = StaticMeshComponent->GetRelativeLocation().Z;
			LockCurrentZ = LockInitialZ;
			LockTargetZ += LockInitialZ;
		}
	}
}
// Called every frame
void UOpenDoor2::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	if (TriggerVolume && GetStaticMesh() && GetStaticMesh()->ActorHasTag("PipeWrench"))
	{

		//UE_LOG(LogTemp, Warning, TEXT("%s"), *GetStaticMesh()->GetName());
		if (b_Lock)
		{
			if (!b_Unlock)
			{
				AnimateDoorUnlock(DeltaTime);
				TimeSecconds = GetWorld()->GetTimeSeconds();
			}
			else
			{
				OpenDoor(DeltaTime);
				TimeSecconds = GetWorld()->GetTimeSeconds();
			}
		}
		else
		{
			OpenDoor(DeltaTime);
			TimeSecconds = GetWorld()->GetTimeSeconds();
		}

		//TimeSecconds = GetWorld()->GetTimeSeconds();
	}
}
void UOpenDoor2::OpenDoor(float DeltaTime)
{
	//GetActorLocation
	FRotator GetActorLocation = GetOwner()->GetActorRotation();
	//Make Lerp
	CurrentYaw = FMath::FInterpTo(CurrentYaw, TargetYaw, DeltaTime, Open_Speed);
	//Set ActorRotation to CurrentYaw
	GetActorLocation.Yaw = CurrentYaw;
	GetOwner()->SetActorRotation(GetActorLocation);
}
void UOpenDoor2::CloseDoor(float DeltaTime)
{
	//GetActorLocation
	FRotator GetActorLocation = GetOwner()->GetActorRotation();
	//Make Lerp
	CurrentYaw = FMath::FInterpTo(CurrentYaw, InitialYaw, DeltaTime, Close_Speed);
	//Set ActorRotation to CurrentYaw
	GetActorLocation.Yaw = CurrentYaw;
	GetOwner()->SetActorRotation(GetActorLocation);
}
float UOpenDoor2::AnimateDoorUnlock(float DeltaTime)
{
	//UE_LOG(LogTemp, Error, TEXT("%i"), Components.Num());
	for (UStaticMeshComponent* StaticMeshComponent : Components)
	{
		if (StaticMeshComponent->ComponentHasTag("Lock"))
		{
			//Make Lerp
			FVector GetActorLocation = StaticMeshComponent->GetRelativeLocation();
			LockCurrentZ = FMath::FInterpConstantTo(LockCurrentZ, LockTargetZ, DeltaTime, UnLock_Speed);
			//Set ActorRotation to LockCurrentZ
			//GetActorLocation.X = 0.f;
			//GetActorLocation.Y = 0.f;
			GetActorLocation.Z = LockCurrentZ;
			StaticMeshComponent->SetRelativeLocation(GetActorLocation);
			if (GetActorLocation.Z == LockTargetZ)
			{
				b_Unlock = true;
				return GetActorLocation.Z;
			}
		}
	}
	return 0.f;
}
AActor* UOpenDoor2::GetStaticMesh()
{
	TArray<AActor*> OverlappingActors{ nullptr };
	TriggerVolume->GetOverlappingActors(OverlappingActors);
	for (AActor* Actor : OverlappingActors)
	{
		if (Actor->ActorHasTag("PipeWrench"))
		{
			return Actor;
			//UE_LOG(LogTemp, Warning, TEXT("[GetStaticMesh] (PipeWrench) Found"));
		}
		else
		{
			//UE_LOG(LogTemp, Error, TEXT("[GetStaticMesh] (PipeWrench) Not Found"));
		}
	}
	AActor* nullptrActor = nullptr;
	return nullptrActor;
}

Train_door.h



#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Engine/TriggerVolume.h"
#include "GameFramework/Actor.h"
#include "GameFramework/Pawn.h"
#include "Train_door.generated.h"


UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class HORRORENGINE_API UTrain_door : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UTrain_door();

protected:
	// Called when the game starts
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
public://Funcs
	void OpenDoor(float DeltaTime);
	void CloseDoor(float DeltaTime);
	//FHitResult GetFirstHit();
	void GetPlayer();
	void ViewPoint(FVector& Location, FRotator& Rotation);
	FVector Location();
	FRotator Rotation();
	//FVector LineTraceEnd();
	void FindDoors();
	void SetUpTriggerVolume();
	void FindPlayDoorSound();
	void PlayDoorSound();
private://PTRs
	TArray<UStaticMeshComponent*> GetStaticMeshes;
	TArray<UStaticMeshComponent*> Get_R_Door;
	TArray<UStaticMeshComponent*> Get_L_Door;
private://Checkers
	bool b_IsComplete = false;
	bool b_IsComplete_Y = false;
	bool b_IsComplete_X = false;
	bool DoorSound = false;
private://Vars 
	TArray<float> R_InitialAxes_Y;
	TArray<float> L_InitialAxes_Y;
	TArray<float> R_InitialAxes_X;
	TArray<float> L_InitialAxes_X;

	TArray<float> R_CurrentAxes_Y;
	TArray<float> L_CurrentAxes_Y;
	TArray<float> R_CurrentAxes_X;
	TArray<float> L_CurrentAxes_X;

	TArray<float> R_TargetAxis_Y;
	TArray<float> L_TargetAxis_Y;
	TArray<float> R_TargetAxis_X;
	TArray<float> L_TargetAxis_X;
	float TargetAxis_X = 100.f;
	float TargetAxis_Y = 10.f;
private://Show in UE
	UPROPERTY(EditAnywhere)
		ATriggerVolume* TriggerVolume = nullptr;
	UPROPERTY(EditAnywhere)
		ATriggerVolume* OnTrain = nullptr;//To Make sure the player on train 
	UPROPERTY(EditAnywhere)
		AActor* ThePlayer;
	UPROPERTY(EditAnywhere)
		float Speed;
	UPROPERTY()
		UAudioComponent* AudioComponent = nullptr;
};

Train_door.cpp


#include "Train_door.h"
#include "Engine/World.h"
#include "Components/InputComponent.h"
#include "Engine/StaticMeshActor.h"
#include "Components/StaticMeshComponent.h"
#include "Components/AudioComponent.h"
// Sets default values for this component's properties
UTrain_door::UTrain_door()
{
	// 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 UTrain_door::BeginPlay()
{
	Super::BeginPlay();
	GetPlayer();
	SetUpTriggerVolume();
	FindPlayDoorSound();
	//Get
	for (UStaticMeshComponent* Door : Get_R_Door)
	{
		R_InitialAxes_Y.Add(Door->GetRelativeLocation().Y);
	}
	for (UStaticMeshComponent* Door : Get_L_Door)
	{
		L_InitialAxes_Y.Add(Door->GetRelativeLocation().Y);
	}
	for (UStaticMeshComponent* Door : Get_R_Door)
	{
		R_InitialAxes_X.Add(Door->GetRelativeLocation().X);
	}
	for (UStaticMeshComponent* Door : Get_L_Door)
	{
		L_InitialAxes_X.Add(Door->GetRelativeLocation().X);
	}
	//Set
	R_CurrentAxes_Y = R_InitialAxes_Y;
	L_CurrentAxes_Y = L_InitialAxes_Y;
	R_TargetAxis_Y  = R_InitialAxes_Y;
	L_TargetAxis_Y  = L_InitialAxes_Y;

	R_CurrentAxes_X = R_InitialAxes_X;
	L_CurrentAxes_X = L_InitialAxes_X;
	R_TargetAxis_X = R_InitialAxes_X;
	L_TargetAxis_X = L_InitialAxes_X;
	int i;
	for (i = 0; i < R_TargetAxis_Y.Num(); i++)
	{
		R_TargetAxis_Y[i] += TargetAxis_Y;
	}
	i = 0;
	for (i; i < L_TargetAxis_Y.Num(); i++)
	{
		L_TargetAxis_Y[i] += TargetAxis_Y;
	}
	for (i = 0; i < R_TargetAxis_X.Num(); i++)
	{
		R_TargetAxis_X[i] += TargetAxis_X;
	}
	i = 0;
	for (i; i < L_TargetAxis_X.Num(); i++)
	{
		L_TargetAxis_X[i] += (TargetAxis_X * -1);
	}
	//UE_LOG(LogTemp, Warning, TEXT("L_TargetAxis_Y: %f  || L_CurrentAxes_Y: %f || L_InitialAxes_Y: %f"), L_TargetAxis_Y[0] , L_CurrentAxes_Y[0], L_InitialAxes_Y[0]);
}
void UTrain_door::SetUpTriggerVolume()
{
	if (!TriggerVolume) { UE_LOG(LogTemp, Error, TEXT("[MISSING] TriggerVolume")); return; }
	FindDoors();
}
void UTrain_door::FindPlayDoorSound()
{
	AudioComponent = GetOwner()->FindComponentByClass<UAudioComponent>();
	if (!AudioComponent) { UE_LOG(LogTemp, Error, TEXT("[MISSING] AudioComponent")); return; }
}
void UTrain_door::FindDoors()
{
	//GetComponent
	 GetOwner()->GetComponents(GetStaticMeshes);
	//ForLoop
	 TArray<UStaticMeshComponent*>TempArray;
	 TArray<UStaticMeshComponent*>TempArray2;
	 for (UStaticMeshComponent* StaticMesh : GetStaticMeshes)
	 {
		 //FindTag
		 if (StaticMesh->ComponentHasTag("R_Door"))
		 {
			TempArray.Add(StaticMesh);
		 }
		 //FindTag
		 else if (StaticMesh->ComponentHasTag("L_Door"))
		 {
			 TempArray2.Add(StaticMesh);
		 }		 
	 }
	 //SaveStaticMeshes
	 Get_R_Door = TempArray;
	 Get_L_Door = TempArray2;
	 //Log
	 UE_LOG(LogTemp, Warning, TEXT("GetStaticMeshes.Num(): %i"), GetStaticMeshes.Num());
	 UE_LOG(LogTemp, Warning, TEXT("Get_R_Door.Num(): %i"), Get_R_Door.Num());
	 UE_LOG(LogTemp, Warning, TEXT("Get_L_Door.Num(): %i"), Get_L_Door.Num());
	 int32 z = 0;
	 for (z; z < Get_L_Door.Num(); z++)
	 {
		 UE_LOG(LogTemp, Warning, TEXT("Doors Left:%i %s"), z, *Get_L_Door[z]->GetFullName());
	 }
}
// Called every frame
void UTrain_door::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	if (TriggerVolume && TriggerVolume->IsOverlappingActor(ThePlayer))
	{
		OpenDoor(DeltaTime);
	}
	else if (TriggerVolume && !TriggerVolume->IsOverlappingActor(ThePlayer))
	{

			CloseDoor(DeltaTime);
		
	}
}
void UTrain_door::OpenDoor(float DeltaTime)
{
	if (!DoorSound)
	{
		UE_LOG(LogTemp, Warning, TEXT("DoorSound"));
		PlayDoorSound();
	}
	int i;
	if (!b_IsComplete_Y)
	{
		UE_LOG(LogTemp, Warning, TEXT("OpenDoor  !b_IsComplete_Y"));
		bool b_IsComplete1 = false;
		bool b_IsComplete2 = false;
		for (UStaticMeshComponent* Door : Get_L_Door)
		{
			FVector R_Door = Door->GetRelativeLocation();
			for (i = 0; i < L_InitialAxes_Y.Num(); i++)
			{
				L_CurrentAxes_Y[i] = FMath::FInterpConstantTo(L_CurrentAxes_Y[i], L_TargetAxis_Y[i], DeltaTime, Speed);
				R_Door.Y = L_CurrentAxes_Y[i];
				Door->SetRelativeLocation(R_Door);
				if (L_CurrentAxes_Y[i] == L_TargetAxis_Y[i])
				{
					b_IsComplete2 = true;
				}
				else
				{
					b_IsComplete2 = false;
				}
			}
		}
		for (UStaticMeshComponent* Door : Get_R_Door)
		{
			FVector R_Door = Door->GetRelativeLocation();
			for (i = 0; i < R_InitialAxes_Y.Num(); i++)
			{
				R_CurrentAxes_Y[i] = FMath::FInterpConstantTo(R_CurrentAxes_Y[i], R_TargetAxis_Y[i], DeltaTime, Speed);
				R_Door.Y = R_CurrentAxes_Y[i];
				Door->SetRelativeLocation(R_Door);
				if (R_CurrentAxes_Y[i] == R_TargetAxis_Y[i])
				{
					b_IsComplete1 = true;
				}
				else
				{
					b_IsComplete1 = false;
				}
			}
		}
		if (b_IsComplete1 && b_IsComplete2)
		{
			b_IsComplete_Y = true;
		}
	}
	else if(!b_IsComplete_X)
	{
		UE_LOG(LogTemp, Warning, TEXT("OpenDoor  !b_IsComplete_X"));
		bool b_IsComplete1 = false;
		bool b_IsComplete2 = false;
		for (UStaticMeshComponent* Door : Get_R_Door) // Fix it
		{
			FVector R_Door = Door->GetRelativeLocation();
			for (i = 0; i < R_InitialAxes_Y.Num(); i++)
			{
				R_CurrentAxes_X[i] = FMath::FInterpConstantTo(R_CurrentAxes_X[i], R_TargetAxis_X[i], DeltaTime, Speed);
				R_Door.X = R_CurrentAxes_X[i];
				Door->SetRelativeLocation(R_Door);
				if (R_CurrentAxes_X[i] == R_TargetAxis_X[i])
				{
					UE_LOG(LogTemp, Error, TEXT("[OpenDoor] R_CurrentAxes_X[i] == R_TargetAxis_X[i]"));

					b_IsComplete1 = true;
				}
				else
				{
					b_IsComplete1 = false;
				}
			}
		}
		for (UStaticMeshComponent* Door : Get_L_Door)
		{
			i = 0;
			FVector L_Door = Door->GetRelativeLocation();
			for (i; i < L_InitialAxes_X.Num(); i++)
			{
				L_CurrentAxes_X[i] = FMath::FInterpConstantTo(L_CurrentAxes_X[i], L_TargetAxis_X[i], DeltaTime, Speed);
				L_Door.X = L_CurrentAxes_X[i];
				Door->SetRelativeLocation(L_Door);
				if (L_CurrentAxes_X[i] == L_TargetAxis_X[i])
				{
					UE_LOG(LogTemp, Error, TEXT("[OpenDoor] L_CurrentAxes_X[i] == L_TargetAxis_X[i]"));
					b_IsComplete2 = true;
				}
				else
				{
					b_IsComplete2 = false;
				}
			}
		}
		if (b_IsComplete1 && b_IsComplete2)
		{
			b_IsComplete_X = true;
		}
	}
}
void UTrain_door::CloseDoor(float DeltaTime)
{
	DoorSound = false;
	int i;
	if(b_IsComplete_X)
	{
		UE_LOG(LogTemp, Warning, TEXT("[CloseDoor]b_IsComplete_X"));
		bool b_IsComplete1 = false;
		bool b_IsComplete2 = false;
		for (UStaticMeshComponent* Door : Get_L_Door)
		{
			FVector L_Door = Door->GetRelativeLocation();
			for (i = 0; i < L_InitialAxes_X.Num(); i++)
			{
				L_CurrentAxes_X[i] = FMath::FInterpConstantTo(L_CurrentAxes_X[i], L_InitialAxes_X[i], DeltaTime, Speed);
				L_Door.X = L_CurrentAxes_X[i];
				Door->SetRelativeLocation(L_Door);
				if (L_CurrentAxes_X[i] == L_InitialAxes_X[i])
				{
					b_IsComplete1 = true;
				}
				else
				{
					b_IsComplete1 = false;
				}
			}
		}
		for (UStaticMeshComponent* Door : Get_R_Door)
		{
			FVector R_Door = Door->GetRelativeLocation();
			for (i = 0; i < R_InitialAxes_X.Num(); i++)
			{
				R_CurrentAxes_X[i] = FMath::FInterpConstantTo(R_CurrentAxes_X[i], R_InitialAxes_X[i], DeltaTime, Speed);
				R_Door.X = R_CurrentAxes_X[i];
				Door->SetRelativeLocation(R_Door);
				if (R_CurrentAxes_X[i] == R_InitialAxes_X[i])
				{
					b_IsComplete2 = true;
				}
				else
				{
					b_IsComplete2 = false;
				}
			}
		}
		if (b_IsComplete1 && b_IsComplete2)
		{
			b_IsComplete_X = false;
		}
	}
	else if (b_IsComplete_Y)
	{
		UE_LOG(LogTemp, Warning, TEXT("[CloseDoor]b_IsComplete_Y"));
		bool b_IsComplete1 = false;
		bool b_IsComplete2 = false;
		for (UStaticMeshComponent* Door : Get_L_Door)
		{
			FVector L_Door = Door->GetRelativeLocation();
			for (i = 0; i < L_InitialAxes_Y.Num(); i++)
			{
				L_CurrentAxes_Y[i] = FMath::FInterpConstantTo(L_CurrentAxes_Y[i], L_InitialAxes_Y[i], DeltaTime, Speed);
				L_Door.Y = L_CurrentAxes_Y[i];
				Door->SetRelativeLocation(L_Door);
				if (L_CurrentAxes_Y[i] == L_InitialAxes_Y[i])
				{
					b_IsComplete1 = true;
				}
				else
				{
					b_IsComplete1 = false;
				}
			}
		}
		i = 0;
		for (UStaticMeshComponent* Door : Get_R_Door)
		{
			FVector R_Door = Door->GetRelativeLocation();
			for (i = 0; i < R_InitialAxes_Y.Num(); i++)
			{
				R_CurrentAxes_Y[i] = FMath::FInterpConstantTo(R_CurrentAxes_Y[i], R_InitialAxes_Y[i], DeltaTime, Speed);
				R_Door.Y = R_CurrentAxes_Y[i];
				Door->SetRelativeLocation(R_Door);
				if (R_CurrentAxes_Y[i] == R_InitialAxes_Y[i])
				{
					b_IsComplete2 = true;
				}
				else
				{
					b_IsComplete2 = false;
				}
			}
		}
		if (b_IsComplete1 && b_IsComplete2)
		{
			UE_LOG(LogTemp, Error, TEXT("b_IsComplete1 && b_IsComplete2"));
			b_IsComplete_Y = false;
		}
	}
}
FVector UTrain_door::Location()
{
	FVector Location;
	FRotator Rotation;
	ViewPoint(Location, Rotation);
	return Location;
}
FRotator UTrain_door::Rotation()
{
	FVector Location;
	FRotator Rotation;
	ViewPoint(Location, Rotation);
	return Rotation;
}
void UTrain_door::GetPlayer()
{
	ThePlayer = GetWorld()->GetFirstPlayerController()->GetViewTarget();
}
void UTrain_door::ViewPoint(FVector& Location, FRotator& Rotation)
{
	GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(Location, Rotation);
}
void UTrain_door::PlayDoorSound()
{
	if (!AudioComponent) {
		UE_LOG(LogTemp, Error, TEXT("[PlayDoorSound] AudioComponent")); return; }
	AudioComponent->Play();
	DoorSound = true;

}

interactWithSomething.h



#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "interactWithSomething.generated.h"

UENUM()
enum class EChooseTransform
{
	b_Rotation,
	b_Location,
};
UENUM()
enum class ERotation
{
	Roll,
	Pitch,
	Yaw,
};
UENUM()
enum class ELocation
{
	X,
	Y,
	Z,
};

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class HORRORENGINE_API UinteractWithSomething : public UActorComponent
{
	GENERATED_BODY()

public:	
	// Sets default values for this component's properties
	UinteractWithSomething();

protected:
	// Called when the game starts
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
public:
	//SetUps
	void SetUpInputComponent();
	// Delegate function
	void CheckAxis();
	void PlayDoorSound();
	//Location
	float OpenAtLocation_X(float DeltaTime);
	float OpenAtLocation_Y(float DeltaTime);
	float OpenAtLocation_Z(float DeltaTime);
	float CloseAtLocation_X(float DeltaTime);//CloseAtLocation
	float CloseAtLocation_Y(float DeltaTime);
	float CloseAtLocation_Z(float DeltaTime);
	//Rotation
	float OpenAtRotation_Roll(float DeltaTime);
	float OpenAtRotation_Pitch(float DeltaTime);
	float OpenAtRotation_Yaw(float DeltaTime);
	float CloseAtRotation_Roll(float DeltaTime);//CloseAtRotation
	float CloseAtRotation_Pitch(float DeltaTime);
	float CloseAtRotation_Yaw(float DeltaTime);
	void FindAudioComponent();
	//Viewpoint
	FRotator PlayerRotation();
	FVector PlayerLocation();
	// Get the First Hit
	FHitResult GetFirstObjectInRange();
	//Ray-Cast
	FVector LineTraceEnd();
private://Checkers
	bool b_SetUpInputComponent = false;
	bool b_CheckAxis = false;
	bool b_OpenAtLocation_Complete = false;
	bool b_TargetAxis_IS_NegativeNumber = false;
	bool b_ObjectIsFound = false;
	bool DoorSound = false;
private://Vars
	float InitialAxis;
	float CurrentAxis;
	FHitResult g_HitResult;
private://SelectBox
	UPROPERTY(EditAnywhere)
		EChooseTransform ChooseTransform;
	//Select the ONLY one Axis you need
	UPROPERTY(EditAnywhere)
		ERotation Rotation;
	//Select the ONLY one Axis you need
	UPROPERTY(EditAnywhere)
		ELocation Location;
private://Checkers
	UPROPERTY(EditAnywhere)
		bool b_Sound = true;
	UPROPERTY(EditAnywhere)
		bool b_HasCloseFunc = true;
	UPROPERTY(EditAnywhere)
		bool b_repeat = false;
private://SetUps
	UPROPERTY(EditAnywhere)
		float TargetAxis = 10.f;
	UPROPERTY(EditAnywhere) // Use FInterpConstantTo Don't use Lerp()
		float Speed = 10.f;
	//The range between the player and object.
	UPROPERTY(EditAnywhere)
		float Range = 200.f;
private://PTRs
	//Input Component
	UPROPERTY()
		UInputComponent* InputComponent = nullptr;
	UPROPERTY()
		UAudioComponent* AudioComponent = nullptr;
};

interactWithSomething.cpp

#include "interactWithSomething.h"
#include "Engine/World.h"
#include "GameFramework/Actor.h"
#include "Components/InputComponent.h"
#include "Components/AudioComponent.h"

#define OUT

//DECLARE_DELEGATE_OneParam(MyDelegate, float);

// Sets default values for this component's properties
UinteractWithSomething::UinteractWithSomething()
{
	// 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 UinteractWithSomething::BeginPlay()
{
	FindAudioComponent();
	Super::BeginPlay();
	//SetUpLerpValue
	SetUpInputComponent();

	if (TargetAxis < 0.f)
	{
		b_TargetAxis_IS_NegativeNumber = true;
	}
	if (ChooseTransform == EChooseTransform::b_Rotation)
	{
		UE_LOG(LogTemp, Warning, TEXT("[BeginPlay] b_Rotation is true"));
		if (Rotation == ERotation::Roll)//Roll
		{
			UE_LOG(LogTemp, Warning, TEXT("[BeginPlay] Rotation is 0"));
			InitialAxis = GetOwner()->GetActorRotation().Roll;
			CurrentAxis = InitialAxis;
			TargetAxis += InitialAxis;
		}
		else if (Rotation == ERotation::Pitch)//Pitch
		{
			InitialAxis = GetOwner()->GetActorRotation().Pitch;
			CurrentAxis = InitialAxis;
			TargetAxis += InitialAxis;
		}
		else if (Rotation == ERotation::Yaw)//Yaw
		{
			InitialAxis = GetOwner()->GetActorRotation().Yaw;
			CurrentAxis = InitialAxis;
			TargetAxis += InitialAxis;
		}
	}
	else if (ChooseTransform == EChooseTransform::b_Location)
	{
		UE_LOG(LogTemp, Warning, TEXT("[BeginPlay] b_Location is true || LocationVal: %i"), Location);
		if (Location == ELocation::X)//X
		{
			UE_LOG(LogTemp, Warning, TEXT("[BeginPlay]X Location is 0"));
			InitialAxis = GetOwner()->GetActorLocation().X;
			CurrentAxis = InitialAxis;
			TargetAxis += InitialAxis;
		}
		else if (Location == ELocation::Y)//Y
		{
			UE_LOG(LogTemp, Warning, TEXT("[BeginPlay]Y Location is 1"));
			InitialAxis = GetOwner()->GetActorLocation().Y;
			CurrentAxis = InitialAxis;
			TargetAxis += InitialAxis;
		}
		else if (Location == ELocation::Z)
		{
			UE_LOG(LogTemp, Warning, TEXT("[BeginPlay]Z Location is 2"));
			InitialAxis = GetOwner()->GetActorLocation().Z;
			CurrentAxis = InitialAxis;
			TargetAxis += InitialAxis;
		}

	}
	else
	{
		UE_LOG(LogTemp, Error, TEXT("[BeginPlay] The Issue is here || %i"), ChooseTransform);
	}
}
void UinteractWithSomething::FindAudioComponent()
{
	AudioComponent = GetOwner()->FindComponentByClass<UAudioComponent>();
	if (!AudioComponent)
	{
		UE_LOG(LogTemp, Error, TEXT("%s: MISSING Audio Component!"), *GetOwner()->GetName());
	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("AudioComponent Was Found"));
	}
}
void UinteractWithSomething::SetUpInputComponent()
{
	InputComponent = GetWorld()->GetFirstPlayerController()->GetPawn()->InputComponent;
	InputComponent->BindAction("Interact", IE_Pressed, this, &UinteractWithSomething::CheckAxis);
}
void UinteractWithSomething::CheckAxis()
{
	UE_LOG(LogTemp, Warning, TEXT("CheckAxis"));
	if (b_CheckAxis)
	{
		return;
	}
	else
	{
		b_CheckAxis = true;
	}
	
}
// Called every frame
void UinteractWithSomething::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	if (b_CheckAxis)
	{
		FHitResult HitResult = GetFirstObjectInRange();
		if (!b_ObjectIsFound)
		{
			g_HitResult = HitResult;
		}
		if (b_repeat && g_HitResult.GetActor() && g_HitResult.GetActor()->ActorHasTag("Interactable") == GetOwner()->ActorHasTag("Interactable") && g_HitResult.GetActor()->GetName() == GetOwner()->GetName()) // 3 conds
		{
			b_ObjectIsFound = true;
			if (ChooseTransform == EChooseTransform::b_Location)
			{
				UE_LOG(LogTemp, Warning, TEXT("b_repeat || Hit Result: %s"), *g_HitResult.GetActor()->GetName());
				if (Location == ELocation::X)
				{
					UE_LOG(LogTemp, Warning, TEXT("The Axis is 'X' = %i"), ELocation::X);
					UE_LOG(LogTemp, Warning, TEXT("The Axis is 'X' LocationVal %i"), Location);
					if (!b_OpenAtLocation_Complete)
					{
						if (OpenAtLocation_X(DeltaTime) == TargetAxis)
						{
							UE_LOG(LogTemp, Warning, TEXT("OpenAtLocation_X = TargetAxis"));
						}
						else
						{
							OpenAtLocation_X(DeltaTime);
						}
					}
					else
					{
						if (b_HasCloseFunc)
						{
							UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = true"));
							UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
							if (CloseAtLocation_X(DeltaTime) == InitialAxis)
							{
								UE_LOG(LogTemp, Warning, TEXT("CloseAtLocation_X = InitialAxis"));
								b_OpenAtLocation_Complete = false;
								b_CheckAxis = false;
							}
							else
							{
								CloseAtLocation_X(DeltaTime);
							}
						}
						else
						{
							UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = false"));
							UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
							b_OpenAtLocation_Complete = false;
							b_CheckAxis = false;
						}

					}

				}
				else if (Location == ELocation::Y)
				{
					UE_LOG(LogTemp, Warning, TEXT("The Axis is 'Y' = %i"), ELocation::Y);
					UE_LOG(LogTemp, Warning, TEXT("The Axis is 'Y' LocationVal %i"), Location);
					if (!b_OpenAtLocation_Complete)
					{
						if (OpenAtLocation_Y(DeltaTime) == TargetAxis)
						{
							UE_LOG(LogTemp, Warning, TEXT("OpenAtLocation_Y = TargetAxis"));
						}
						else
						{
							OpenAtLocation_Y(DeltaTime);
						}
					}
					else
					{
						if (b_HasCloseFunc)
						{
							UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = true"));
							UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
							if (CloseAtLocation_Y(DeltaTime) == InitialAxis)
							{
								UE_LOG(LogTemp, Warning, TEXT("CloseAtLocation_Y = InitialAxis"));
								b_OpenAtLocation_Complete = false;
								b_CheckAxis = false;
							}
							else
							{
								CloseAtLocation_Y(DeltaTime);
							}
						}
						else
						{
							UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = false"));
							UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
							b_OpenAtLocation_Complete = false;
							b_CheckAxis = false;
						}

					}
				}
				else if (Location == ELocation::Z)
				{
					UE_LOG(LogTemp, Warning, TEXT("The Axis is 'Z' = %i"), ELocation::Z);
					UE_LOG(LogTemp, Warning, TEXT("The Axis is 'Z' LocationVal %i"), Location);
					if (!b_OpenAtLocation_Complete)
					{
						if (OpenAtLocation_Z(DeltaTime) == TargetAxis)
						{
							UE_LOG(LogTemp, Warning, TEXT("OpenAtLocation_Z = TargetAxis"));
						}
						else
						{
							OpenAtLocation_Z(DeltaTime);
						}
					}
					else
					{
						if (b_HasCloseFunc)
						{
							UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = true"));
							UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
							if (CloseAtLocation_Z(DeltaTime) == InitialAxis)
							{
								UE_LOG(LogTemp, Warning, TEXT("CloseAtLocation_Z = InitialAxis"));
								b_OpenAtLocation_Complete = false;
								b_CheckAxis = false;
							}
							else
							{
								CloseAtLocation_Z(DeltaTime);
							}
						}
						else
						{
							UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = false"));
							UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
							b_OpenAtLocation_Complete = false;
							b_CheckAxis = false;
						}

					}
				}
			}
			if (ChooseTransform == EChooseTransform::b_Rotation)
			{
				UE_LOG(LogTemp, Warning, TEXT("[TickComponent] b_Rotation"));
				if (Rotation == ERotation::Roll)
				{
					UE_LOG(LogTemp, Warning, TEXT("The Axis is 'Roll'"));
					if (!b_OpenAtLocation_Complete)
					{
						if (OpenAtRotation_Roll(DeltaTime) == TargetAxis)
						{
							UE_LOG(LogTemp, Warning, TEXT("OpenAtRotation_Roll = TargetAxis"));
						}
						else
						{
							OpenAtRotation_Roll(DeltaTime);
						}
					}
					else
					{
						if (b_HasCloseFunc)
						{
							UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = true"));
							UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
							if (CloseAtRotation_Roll(DeltaTime) == InitialAxis)
							{
								UE_LOG(LogTemp, Warning, TEXT("CloseAtRotation_Roll = InitialAxis"));
								b_OpenAtLocation_Complete = false;
								b_CheckAxis = false;
							}
							else
							{
								CloseAtRotation_Roll(DeltaTime);
							}
						}
						else
						{
							UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = false"));
							UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
							b_OpenAtLocation_Complete = false;
							b_CheckAxis = false;
						}

					}
				}
				else if (Rotation == ERotation::Pitch)
				{
					UE_LOG(LogTemp, Warning, TEXT("The Axis is 'Pitch'"));

					if (!b_OpenAtLocation_Complete)
					{
						if (OpenAtRotation_Pitch(DeltaTime) == TargetAxis)
						{
							UE_LOG(LogTemp, Warning, TEXT("OpenAtRotation_Pitch = TargetAxis"));
						}
						else
						{
							OpenAtRotation_Pitch(DeltaTime);
						}
					}
					else
					{
						if (b_HasCloseFunc)
						{
							UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = true"));
							UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
							if (CloseAtRotation_Pitch(DeltaTime) == InitialAxis)
							{
								UE_LOG(LogTemp, Warning, TEXT("CloseAtRotation_Pitch = InitialAxis"));
								b_OpenAtLocation_Complete = false;
								b_CheckAxis = false;
							}
							else
							{
								CloseAtRotation_Pitch(DeltaTime);
							}
						}
						else
						{
							UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = false"));
							UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
							b_OpenAtLocation_Complete = false;
							b_CheckAxis = false;
						}

					}
				}
				else if (Rotation == ERotation::Yaw)
				{
					UE_LOG(LogTemp, Warning, TEXT("The Axis is 'Yaw'"));
					if (!b_OpenAtLocation_Complete)
					{
						if (OpenAtRotation_Yaw(DeltaTime) == TargetAxis)
						{
							UE_LOG(LogTemp, Warning, TEXT("OpenAtRotation_Yaw = TargetAxis"));
						}
						else
						{
							OpenAtRotation_Yaw(DeltaTime);
						}
					}
					else
					{
						if (b_HasCloseFunc)
						{
							UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = true"));
							UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
							if (CloseAtRotation_Yaw(DeltaTime) == InitialAxis)
							{
								UE_LOG(LogTemp, Warning, TEXT("CloseAtRotation_Yaw = InitialAxis"));
								b_OpenAtLocation_Complete = false;
								b_CheckAxis = false;
							}
							else
							{
								CloseAtRotation_Yaw(DeltaTime);
							}
						}
						else
						{
							UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = false"));
							UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
							b_OpenAtLocation_Complete = false;
							b_CheckAxis = false;
						}
					}
				}
			}
		}
		else if (HitResult.GetActor() && HitResult.GetActor()->ActorHasTag("Interactable") == GetOwner()->ActorHasTag("Interactable") && HitResult.GetActor()->GetName() == GetOwner()->GetName())
		{
		UE_LOG(LogTemp, Warning, TEXT("Hit Result: %s"), *HitResult.GetActor()->GetName());
		if (ChooseTransform == EChooseTransform::b_Location)
		{
			if (Location == ELocation::X)
			{
				UE_LOG(LogTemp, Warning, TEXT("The Axis is 'X' = %i"), ELocation::X);
				UE_LOG(LogTemp, Warning, TEXT("The Axis is 'X' LocationVal %i"), Location);
				if (!b_OpenAtLocation_Complete)
				{
					if (OpenAtLocation_X(DeltaTime) == TargetAxis)
					{
						UE_LOG(LogTemp, Warning, TEXT("OpenAtLocation_X = TargetAxis"));
					}
					else
					{
						OpenAtLocation_X(DeltaTime);
					}
				}
				else
				{
					if (b_HasCloseFunc)
					{
						UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = true"));
						UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
						if (CloseAtLocation_X(DeltaTime) == InitialAxis)
						{
							UE_LOG(LogTemp, Warning, TEXT("CloseAtLocation_X = InitialAxis"));
							b_OpenAtLocation_Complete = false;
							b_CheckAxis = false;
						}
						else
						{
							CloseAtLocation_X(DeltaTime);
						}
					}
					else
					{
						UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = false"));
						UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
						b_OpenAtLocation_Complete = false;
						b_CheckAxis = false;
					}

				}

			}
			else if (Location == ELocation::Y)
			{
				UE_LOG(LogTemp, Warning, TEXT("The Axis is 'Y' = %i"), ELocation::Y);
				UE_LOG(LogTemp, Warning, TEXT("The Axis is 'Y' LocationVal %i"), Location);
				if (!b_OpenAtLocation_Complete)
				{
					if (OpenAtLocation_Y(DeltaTime) == TargetAxis)
					{
						UE_LOG(LogTemp, Warning, TEXT("OpenAtLocation_Y = TargetAxis"));
					}
					else
					{
						OpenAtLocation_Y(DeltaTime);
					}
				}
				else
				{
					if (b_HasCloseFunc)
					{
						UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = true"));
						UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
						if (CloseAtLocation_Y(DeltaTime) == InitialAxis)
						{
							UE_LOG(LogTemp, Warning, TEXT("CloseAtLocation_Y = InitialAxis"));
							b_OpenAtLocation_Complete = false;
							b_CheckAxis = false;
						}
						else
						{
							CloseAtLocation_Y(DeltaTime);
						}
					}
					else
					{
						UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = false"));
						UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
						b_OpenAtLocation_Complete = false;
						b_CheckAxis = false;
					}

				}
			}
			else if (Location == ELocation::Z)
			{
				UE_LOG(LogTemp, Warning, TEXT("The Axis is 'Z' = %i"), ELocation::Z);
				UE_LOG(LogTemp, Warning, TEXT("The Axis is 'Z' LocationVal %i"), Location);
				if (!b_OpenAtLocation_Complete)
				{
					if (OpenAtLocation_Z(DeltaTime) == TargetAxis)
					{
						UE_LOG(LogTemp, Warning, TEXT("OpenAtLocation_Z = TargetAxis"));
					}
					else
					{
						OpenAtLocation_Z(DeltaTime);
					}
				}
				else
				{
					if (b_HasCloseFunc)
					{
						UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = true"));
						UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
						if (CloseAtLocation_Z(DeltaTime) == InitialAxis)
						{
							UE_LOG(LogTemp, Warning, TEXT("CloseAtLocation_Z = InitialAxis"));
							b_OpenAtLocation_Complete = false;
							b_CheckAxis = false;
						}
						else
						{
							CloseAtLocation_Z(DeltaTime);
						}
					}
					else
					{
						UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = false"));
						UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
						b_OpenAtLocation_Complete = false;
						b_CheckAxis = false;
					}

				}
			}
		}
		if (ChooseTransform == EChooseTransform::b_Rotation)
		{
			UE_LOG(LogTemp, Warning, TEXT("[TickComponent] b_Rotation"));
			if (Rotation == ERotation::Roll)
			{
				UE_LOG(LogTemp, Warning, TEXT("The Axis is 'Roll'"));
				if (!b_OpenAtLocation_Complete)
				{
					if (OpenAtRotation_Roll(DeltaTime) == TargetAxis)
					{
						UE_LOG(LogTemp, Warning, TEXT("OpenAtRotation_Roll = TargetAxis"));
					}
					else
					{
						OpenAtRotation_Roll(DeltaTime);
					}
				}
				else
				{
					if (b_HasCloseFunc)
					{
						UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = true"));
						UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
						if (CloseAtRotation_Roll(DeltaTime) == InitialAxis)
						{
							UE_LOG(LogTemp, Warning, TEXT("CloseAtRotation_Roll = InitialAxis"));
							b_OpenAtLocation_Complete = false;
							b_CheckAxis = false;
						}
						else
						{
							CloseAtRotation_Roll(DeltaTime);
						}
					}
					else
					{
						UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = false"));
						UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
						b_OpenAtLocation_Complete = false;
						b_CheckAxis = false;
					}

				}
			}
			else if (Rotation == ERotation::Pitch)
			{
				UE_LOG(LogTemp, Warning, TEXT("The Axis is 'Pitch'"));

				if (!b_OpenAtLocation_Complete)
				{
					if (OpenAtRotation_Pitch(DeltaTime) == TargetAxis)
					{
						UE_LOG(LogTemp, Warning, TEXT("OpenAtRotation_Pitch = TargetAxis"));
					}
					else
					{
						OpenAtRotation_Pitch(DeltaTime);
					}
				}
				else
				{
					if (b_HasCloseFunc)
					{
						UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = true"));
						UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
						if (CloseAtRotation_Pitch(DeltaTime) == InitialAxis)
						{
							UE_LOG(LogTemp, Warning, TEXT("CloseAtRotation_Pitch = InitialAxis"));
							b_OpenAtLocation_Complete = false;
							b_CheckAxis = false;
						}
						else
						{
							CloseAtRotation_Pitch(DeltaTime);
						}
					}
					else
					{
						UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = false"));
						UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
						b_OpenAtLocation_Complete = false;
						b_CheckAxis = false;
					}

				}
			}
			else if (Rotation == ERotation::Yaw)
			{
				UE_LOG(LogTemp, Warning, TEXT("The Axis is 'Yaw'"));
				if (!b_OpenAtLocation_Complete)
				{
					if (OpenAtRotation_Yaw(DeltaTime) == TargetAxis)
					{
						UE_LOG(LogTemp, Warning, TEXT("OpenAtRotation_Yaw = TargetAxis"));
					}
					else
					{
						OpenAtRotation_Yaw(DeltaTime);
					}
				}
				else
				{
					if (b_HasCloseFunc)
					{
						UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = true"));
						UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
						if (CloseAtRotation_Yaw(DeltaTime) == InitialAxis)
						{
							UE_LOG(LogTemp, Warning, TEXT("CloseAtRotation_Yaw = InitialAxis"));
							b_OpenAtLocation_Complete = false;
							b_CheckAxis = false;
						}
						else
						{
							CloseAtRotation_Yaw(DeltaTime);
						}
					}
					else
					{
						UE_LOG(LogTemp, Warning, TEXT("b_HasCloseFunc = false"));
						UE_LOG(LogTemp, Warning, TEXT("b_OpenAtLocation_Complete = true"));
						b_OpenAtLocation_Complete = false;
						b_CheckAxis = false;
					}
				}
			}
		}
		}
		else 
		{
			UE_LOG(LogTemp, Error, TEXT("[TickComponent] There is no actor for interacting"));
			b_CheckAxis = false;
		}
	}
}
// [Open] AtLocation
float UinteractWithSomething::OpenAtLocation_X(float DeltaTime)
{
	if (  b_Sound && !DoorSound )
	{
		PlayDoorSound();
	}
	if (b_repeat)
	{
		FVector TheLocation = g_HitResult.GetActor()->GetActorLocation();
		UE_LOG(LogTemp, Warning, TEXT("Inside OpenAtLocation_X"));
		if (!g_HitResult.GetActor()) { return InitialAxis; }
		//Lerp
		CurrentAxis = FMath::FInterpConstantTo(CurrentAxis, TargetAxis, DeltaTime, Speed);
		TheLocation.X = CurrentAxis;
		GetOwner()->SetActorLocation(TheLocation);
		if (TheLocation.X == TargetAxis) 
		{
			DoorSound = false;
			if (b_HasCloseFunc)
			{
				b_OpenAtLocation_Complete = true;
				CloseAtLocation_X(DeltaTime);
				return TargetAxis;
			}
			else
			{
				b_OpenAtLocation_Complete = true;
				return TargetAxis;
			}
		}
	}
	else
	{
		FHitResult HitResult = GetFirstObjectInRange();
		UE_LOG(LogTemp, Warning, TEXT("Inside OpenAtLocation_X"));
		if (!HitResult.GetActor()) { return InitialAxis; }
		//Lerp
		FVector TheLocation = HitResult.GetActor()->GetActorLocation();
		CurrentAxis = FMath::FInterpConstantTo(CurrentAxis, TargetAxis, DeltaTime, Speed);
		TheLocation.X = CurrentAxis;
		GetOwner()->SetActorLocation(TheLocation);
		if (TheLocation.X == TargetAxis)
		{
			DoorSound = false;
			if (b_HasCloseFunc)
			{
				b_OpenAtLocation_Complete = true;
				CloseAtLocation_X(DeltaTime);
				return TargetAxis;
			}
			else
			{
				b_OpenAtLocation_Complete = true;
				return TargetAxis;
			}
		}
	}
	return InitialAxis;
}
float UinteractWithSomething::OpenAtLocation_Y(float DeltaTime)
{
	PlayDoorSound();
	if (b_repeat)
	{
		FVector TheLocation = g_HitResult.GetActor()->GetActorLocation();
		UE_LOG(LogTemp, Warning, TEXT("Inside OpenAtLocation_Y"));
		if (!g_HitResult.GetActor()) { return InitialAxis; }
		//Lerp
		CurrentAxis = FMath::FInterpConstantTo(CurrentAxis, TargetAxis, DeltaTime, Speed);
		TheLocation.Y = CurrentAxis;
		GetOwner()->SetActorLocation(TheLocation);
		if (TheLocation.Y == TargetAxis)
		{
			DoorSound = false;
			if (b_HasCloseFunc)
			{
				b_OpenAtLocation_Complete = true;
				CloseAtLocation_Y(DeltaTime);
				return TargetAxis;
			}
			else
			{
				b_OpenAtLocation_Complete = true;
				return TargetAxis;
			}
		}
	}
	else
	{
		FHitResult HitResult = GetFirstObjectInRange();
		UE_LOG(LogTemp, Warning, TEXT("Inside OpenAtLocation_Y"));
		if (!HitResult.GetActor()) { return InitialAxis; }
		//Lerp
		FVector TheLocation = HitResult.GetActor()->GetActorLocation();
		CurrentAxis = FMath::FInterpConstantTo(CurrentAxis, TargetAxis, DeltaTime, Speed);
		TheLocation.Y = CurrentAxis;
		GetOwner()->SetActorLocation(TheLocation);
		if (TheLocation.Y == TargetAxis)
		{
			DoorSound = false;
			if (b_HasCloseFunc)
			{
				b_OpenAtLocation_Complete = true;
				CloseAtLocation_Y(DeltaTime);
				return TargetAxis;
			}
			else
			{
				b_OpenAtLocation_Complete = true;
				return TargetAxis;
			}
		}
	}
	return InitialAxis;
}
float UinteractWithSomething::OpenAtLocation_Z(float DeltaTime)
{
	PlayDoorSound();
	if (b_repeat)
	{
		UE_LOG(LogTemp, Warning, TEXT("Inside OpenAtLocation_Z"));
		if (!g_HitResult.GetActor()) { return InitialAxis; }
		//Lerp
		FVector TheLocation = g_HitResult.GetActor()->GetActorLocation();
		CurrentAxis = FMath::FInterpConstantTo(CurrentAxis, TargetAxis, DeltaTime, Speed);
		TheLocation.Z = CurrentAxis;
		GetOwner()->SetActorLocation(TheLocation);
		if (TheLocation.Z == TargetAxis)
		{
			DoorSound = false;
			if (b_HasCloseFunc)
			{
				b_OpenAtLocation_Complete = true;
				CloseAtLocation_Z(DeltaTime);
				return TargetAxis;
			}
			else
			{
				b_OpenAtLocation_Complete = true;
				return TargetAxis;
			}
		}
	}
	else
	{
		FHitResult HitResult = GetFirstObjectInRange();
		UE_LOG(LogTemp, Warning, TEXT("Inside OpenAtLocation_Z"));
		if (!HitResult.GetActor()) { return InitialAxis; }
		//Lerp
		FVector TheLocation = HitResult.GetActor()->GetActorLocation();
		CurrentAxis = FMath::FInterpConstantTo(CurrentAxis, TargetAxis, DeltaTime, Speed);
		TheLocation.Z = CurrentAxis;
		GetOwner()->SetActorLocation(TheLocation);
		if (TheLocation.Z == TargetAxis)
		{
			DoorSound = false;
			if (b_HasCloseFunc)
			{
				b_OpenAtLocation_Complete = true;
				CloseAtLocation_Z(DeltaTime);
				return TargetAxis;
			}
			else
			{
				b_OpenAtLocation_Complete = true;
				return TargetAxis;
			}
		}
	}
	return InitialAxis;
}

// [Close] AtLocation
float UinteractWithSomething::CloseAtLocation_X(float DeltaTime)
{
	if (b_Sound && !DoorSound)
	{
		PlayDoorSound();
	}
	if (b_repeat)
	{
		if (!g_HitResult.GetActor()) { return InitialAxis; }
		UE_LOG(LogTemp, Warning, TEXT("inside The CloseAtLocation_X function"));
		//Lerp
		FVector TheLocation = g_HitResult.GetActor()->GetActorLocation();
		CurrentAxis = FMath::FInterpConstantTo(CurrentAxis, InitialAxis, DeltaTime, Speed);
		TheLocation.X = CurrentAxis;
		GetOwner()->SetActorLocation(TheLocation);
		if (CurrentAxis == InitialAxis)
		{
			DoorSound = false;
			return InitialAxis;
		}

	}
	else
	{
		FHitResult HitResult = GetFirstObjectInRange();
		UE_LOG(LogTemp, Warning, TEXT("inside The CloseAtLocation_X function"));
		//Lerp
		FVector TheLocation = HitResult.GetActor()->GetActorLocation();
		CurrentAxis = FMath::FInterpConstantTo(CurrentAxis, InitialAxis, DeltaTime, Speed);
		TheLocation.X = CurrentAxis;
		GetOwner()->SetActorLocation(TheLocation);
		if (CurrentAxis == InitialAxis)
		{
			DoorSound = false;
			return InitialAxis;
		}
	}

	return TargetAxis;
}
float UinteractWithSomething::CloseAtLocation_Y(float DeltaTime)
{
	if (  b_Sound && !DoorSound )
	{
		PlayDoorSound();
	}
	if (b_repeat)
	{
		if (!g_HitResult.GetActor()) { return InitialAxis; }
		UE_LOG(LogTemp, Warning, TEXT("inside The CloseAtLocation_X function"));
		//Lerp
		FVector TheLocation = g_HitResult.GetActor()->GetActorLocation();
		CurrentAxis = FMath::FInterpConstantTo(CurrentAxis, InitialAxis, DeltaTime, Speed);
		TheLocation.Y = CurrentAxis;
		GetOwner()->SetActorLocation(TheLocation);
		if (CurrentAxis == InitialAxis)
		{
			DoorSound = false;
			return InitialAxis;
		}

	}
	else 
	{
		FHitResult HitResult = GetFirstObjectInRange();
		UE_LOG(LogTemp, Warning, TEXT("inside The CloseAtLocation_Y function"));
		if (!HitResult.GetActor()) { return InitialAxis; }
		//Lerp
		FVector TheLocation = HitResult.GetActor()->GetActorLocation();
		CurrentAxis = FMath::FInterpConstantTo(CurrentAxis, InitialAxis, DeltaTime, Speed);
		TheLocation.Y = CurrentAxis;
		GetOwner()->SetActorLocation(TheLocation);
		if (CurrentAxis == InitialAxis)
		{
			DoorSound = false;
			return InitialAxis;
		}
	}
	return TargetAxis;
}
float UinteractWithSomething::CloseAtLocation_Z(float DeltaTime)
{
	if (  b_Sound && !DoorSound )
	{
		PlayDoorSound();
	}
	if (b_repeat)
	{
		if (!g_HitResult.GetActor()) { return InitialAxis; }
		UE_LOG(LogTemp, Warning, TEXT("inside The CloseAtLocation_Z function"));
		//Lerp
		FVector TheLocation = g_HitResult.GetActor()->GetActorLocation();
		CurrentAxis = FMath::FInterpConstantTo(CurrentAxis, InitialAxis, DeltaTime, Speed);
		TheLocation.Z = CurrentAxis;
		GetOwner()->SetActorLocation(TheLocation);
		if (CurrentAxis == InitialAxis)
		{
			DoorSound = false;
			return InitialAxis;
		}
	}
	else
	{
		FHitResult HitResult = GetFirstObjectInRange();
		UE_LOG(LogTemp, Warning, TEXT("inside The CloseAtLocation_Z function"));
		if (!HitResult.GetActor()) { return InitialAxis; }
		//Lerp
		FVector TheLocation = HitResult.GetActor()->GetActorLocation();
		CurrentAxis = FMath::FInterpConstantTo(CurrentAxis, InitialAxis, DeltaTime, Speed);
		TheLocation.Z = CurrentAxis;
		GetOwner()->SetActorLocation(TheLocation);
		if (CurrentAxis == InitialAxis)
		{
			DoorSound = false;
			return InitialAxis;
		}
	}
	return TargetAxis;
}

// [Open] AtRotation
float UinteractWithSomething::OpenAtRotation_Roll(float DeltaTime)
{
	if (  b_Sound && !DoorSound )
	{
		PlayDoorSound();
	}
	FHitResult HitResult = GetFirstObjectInRange();
	UE_LOG(LogTemp, Warning, TEXT("Inside OpenAtRotation_Roll"));
	if (!HitResult.GetActor()) { return InitialAxis; }
	//Lerp
	FRotator TheLocation = HitResult.GetActor()->GetActorRotation();
	CurrentAxis = FMath::FInterpConstantTo(CurrentAxis, TargetAxis, DeltaTime, Speed);
	TheLocation.Roll = CurrentAxis;
	GetOwner()->SetActorRotation(TheLocation);
	if (TheLocation.Roll == TargetAxis)
	{
		DoorSound = false;
		if (b_HasCloseFunc)
		{
			b_OpenAtLocation_Complete = true;
			CloseAtRotation_Roll(DeltaTime);
			return TargetAxis;
		}
		else
		{
			b_OpenAtLocation_Complete = true;
			return TargetAxis;
		}
	}
	return InitialAxis;
}
float UinteractWithSomething::OpenAtRotation_Pitch(float DeltaTime)
{
	if (  b_Sound && !DoorSound )
	{
		PlayDoorSound();
	}
	FHitResult HitResult = GetFirstObjectInRange();
	UE_LOG(LogTemp, Warning, TEXT("Inside OpenAtRotation_Pitch"));
	if (!HitResult.GetActor()) { return InitialAxis; }
	//Lerp
	FRotator TheLocation = HitResult.GetActor()->GetActorRotation();
	CurrentAxis = FMath::FInterpConstantTo(CurrentAxis, TargetAxis, DeltaTime, Speed);
	TheLocation.Pitch = CurrentAxis;
	GetOwner()->SetActorRotation(TheLocation);
	if (TheLocation.Pitch == TargetAxis)
	{
		DoorSound = false;
		if (b_HasCloseFunc)
		{
			b_OpenAtLocation_Complete = true;
			CloseAtRotation_Pitch(DeltaTime);
			return TargetAxis;
		}
		else
		{
			b_OpenAtLocation_Complete = true;
			return TargetAxis;
		}
	}
	return InitialAxis;
}
float UinteractWithSomething::OpenAtRotation_Yaw(float DeltaTime)
{
	if (  b_Sound && !DoorSound )
	{
		PlayDoorSound();
	}
	FHitResult HitResult = GetFirstObjectInRange();
	if (!HitResult.GetActor()) { return InitialAxis; }
	UE_LOG(LogTemp, Warning, TEXT("Inside OpenAtRotation_Yaw"));
	UE_LOG(LogTemp, Warning, TEXT("[OpenAtRotation_Yaw]Actor's name: %s"), *HitResult.GetActor()->GetName()); 
	//Lerp
	FRotator TheLocation = HitResult.GetActor()->GetActorRotation();
	CurrentAxis = FMath::FInterpConstantTo(CurrentAxis, TargetAxis, DeltaTime, Speed);
	TheLocation.Yaw = CurrentAxis;
	GetOwner()->SetActorRotation(TheLocation);
	if (TheLocation.Yaw == TargetAxis)
	{
		DoorSound = false;
		if (b_HasCloseFunc)
		{
			b_OpenAtLocation_Complete = true;
			CloseAtRotation_Yaw(DeltaTime);
			return TargetAxis;
		}
		else
		{
			b_OpenAtLocation_Complete = true;
			return TargetAxis;
		}
	}
	return InitialAxis;
}

//[Close] AtRotation
float UinteractWithSomething::CloseAtRotation_Roll(float DeltaTime)
{
	if (  b_Sound && !DoorSound )
	{
		PlayDoorSound();
	}
	PlayDoorSound();
	FHitResult HitResult = GetFirstObjectInRange();
	UE_LOG(LogTemp, Warning, TEXT("inside The CloseAtRotation_Roll function"));
	if (!HitResult.GetActor()) { return InitialAxis; }
	//Lerp
	FRotator TheLocation = HitResult.GetActor()->GetActorRotation();
	CurrentAxis = FMath::FInterpConstantTo(CurrentAxis, InitialAxis, DeltaTime, Speed);
	TheLocation.Roll = CurrentAxis;
	GetOwner()->SetActorRotation(TheLocation);
	if (CurrentAxis == TargetAxis)
	{
		DoorSound = false;
		return InitialAxis;
	}
	return TargetAxis;
}
float UinteractWithSomething::CloseAtRotation_Pitch(float DeltaTime)
{
	if (  b_Sound && !DoorSound )
	{
		PlayDoorSound();
	}
	FHitResult HitResult = GetFirstObjectInRange();
	UE_LOG(LogTemp, Warning, TEXT("inside The CloseAtRotation_Pitch function"));
	if (!HitResult.GetActor()) { return InitialAxis; }
	//Lerp
	FRotator TheLocation = HitResult.GetActor()->GetActorRotation();
	CurrentAxis = FMath::FInterpConstantTo(CurrentAxis, InitialAxis, DeltaTime, Speed);
	TheLocation.Pitch = CurrentAxis;
	GetOwner()->SetActorRotation(TheLocation);
	if (CurrentAxis == TargetAxis)
	{
		DoorSound = false;
		return InitialAxis;
	}
	return TargetAxis;
}
float UinteractWithSomething::CloseAtRotation_Yaw(float DeltaTime)
{
	if (  b_Sound && !DoorSound )
	{
		PlayDoorSound();
	}
	FHitResult HitResult = GetFirstObjectInRange();
	UE_LOG(LogTemp, Warning, TEXT("inside The CloseAtRotation_Yaw function"));
	if (!HitResult.GetActor()) { return InitialAxis; }
	//Lerp
	FRotator TheLocation = HitResult.GetActor()->GetActorRotation();
	CurrentAxis = FMath::FInterpConstantTo(CurrentAxis, InitialAxis, DeltaTime, Speed);
	TheLocation.Yaw = CurrentAxis;
	GetOwner()->SetActorRotation(TheLocation);
	if (CurrentAxis == TargetAxis)
	{
		DoorSound = false;
		return InitialAxis;
	}
	return TargetAxis;
}

FHitResult UinteractWithSomething::GetFirstObjectInRange()
{
	FHitResult HitResult;
	FCollisionQueryParams Params(FName(""), false);
	bool b_HitResult = GetWorld()->LineTraceSingleByObjectType
	(
		HitResult,
		PlayerLocation(),
		LineTraceEnd(),
		ECollisionChannel::ECC_WorldStatic,
		Params
	);
	if (b_HitResult)
	{
		UE_LOG(LogTemp, Warning, TEXT("GetFirstObjectInRange"));
	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("GetFirstObjectInRange Error"));
	}
	return HitResult;
}
FVector UinteractWithSomething::LineTraceEnd()
{
	return PlayerLocation() + PlayerRotation().Vector() * Range;
}
FRotator UinteractWithSomething::PlayerRotation()
{
	FVector playerLocation;
	FRotator playerRotation;
	GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(OUT playerLocation, OUT playerRotation);
	return playerRotation;
}
FVector UinteractWithSomething::PlayerLocation()
{
	FVector playerLocation;
	FRotator playerRotation;
	GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(OUT playerLocation, OUT playerRotation);
	return playerLocation;
}
void UinteractWithSomething::PlayDoorSound()
{
	if (!AudioComponent) {
		UE_LOG(LogTemp, Error, TEXT("[PlayDoorSound] AudioComponent")); return;
	}
	AudioComponent->Play();
	DoorSound = true;

}
1 Like

Grabbar.h

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "PhysicsEngine/PhysicsHandleComponent.h"
#include "Components/SpotLightComponent.h"
#include "Grabbar.generated.h"


UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class HORRORENGINE_API UGrabbar : public UActorComponent
{
	GENERATED_BODY()

public:
	// Sets default values for this component's properties
	UGrabbar();

protected:
	// Called when the game starts
	virtual void BeginPlay() override;

public:
	// Called every frame
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

private://Checkers
	FVector TempLocation;
private://Variables
	//PTR
	UPROPERTY()
		UInputComponent* InputComponent = nullptr;
	UPROPERTY()
		UPhysicsHandleComponent* PhysicsHandle = nullptr;
	UPROPERTY()
		UPhysicsHandleComponent* PhysicsHandle2 = nullptr;
	//SpotLight
	USpotLightComponent* SpotLight = nullptr;
	TArray<UPhysicsHandleComponent*> Components;

	//Range
	float DefaultRange = 200.f;
private://Functions

	//SetUps
	void SetUpInputComponent();
	void FindPhysicsHandleComponent();
	//Grabber
	void Grab();
	void Release();
	void Grab_FlashLight();
	void Release_FlashLight();
	void TurnOnLight();
	void TurnOffLight();
	//Player Viewpoint
	FVector PlayerLocation();
	FRotator PlayerRotation();
	FVector TraceEnd(bool CustomRange, float p_Range = 0.f, float Dir = 0.f, float Roll = 0.f, float Pitch = 0.f);
	//Add New Comp
	void AddNewComp();
	//Ray-Casts
	FHitResult LineTracing_FlashLight();
	FHitResult LineTracing_Other();


};

Grabbar.cpp


#include "Grabbar.h"
#include "GameFramework/PlayerController.h"
#include "Engine/World.h"
#include "Components/InputComponent.h"
#include "Components/SceneComponent.h"

// Sets default values for this component's properties
UGrabbar::UGrabbar()
{
	// 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 UGrabbar::BeginPlay()
{
	Super::BeginPlay();

	SetUpInputComponent();
	FindPhysicsHandleComponent();
	AddNewComp();
	if (!PhysicsHandle) { UE_LOG(LogTemp, Error, TEXT("[Grabber.BeginPlay] PhysicsHandle Not Set"));  return; }
	if (!PhysicsHandle2) { UE_LOG(LogTemp, Error, TEXT("[Grabber.BeginPlay] PhysicsHandle2 Not Set")); return; }
	UE_LOG(LogTemp, Warning, TEXT("PhysicsHandleComponents.Num(): %i"), Components.Num());
	for (UPhysicsHandleComponent* Component : Components)
	{
		UE_LOG(LogTemp, Warning, TEXT("PhysicsHandleComponent's Name: %s"), *Component->GetReadableName());
	}
	TempLocation = TraceEnd(true, 45.f);
}
void UGrabbar::FindPhysicsHandleComponent()
{
	PhysicsHandle = GetOwner()->FindComponentByClass<UPhysicsHandleComponent>();
	if (PhysicsHandle)
	{
		UE_LOG(LogTemp, Warning, TEXT("PhysicsHandle != Nullptr")); // Test
	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("PhysicsHandle = Nullptr")); // Test
	}
}
void UGrabbar::SetUpInputComponent()
{
	UE_LOG(LogTemp, Warning, TEXT("SetUpInputComponent")); // Test
	InputComponent = GetOwner()->InputComponent;
	InputComponent->BindAction("Grab", IE_Pressed, this, &UGrabbar::Grab);
	InputComponent->BindAction("Grab", IE_DoubleClick, this, &UGrabbar::Release);
	InputComponent->BindAction("GrabFlashLight", IE_Pressed, this, &UGrabbar::Grab_FlashLight);
	InputComponent->BindAction("GrabFlashLight", IE_DoubleClick, this, &UGrabbar::Release_FlashLight);
	InputComponent->BindAction("TurnOn_Off_flashlight", IE_Pressed, this, &UGrabbar::TurnOnLight);
	InputComponent->BindAction("TurnOn_Off_flashlight", IE_DoubleClick, this, &UGrabbar::TurnOffLight);
}
void UGrabbar::Grab()
{
	// Get First Hit
	FHitResult HitResult = LineTracing_Other();
	UPrimitiveComponent* ComponentToGrab = HitResult.GetComponent();
	// Check
	if (!PhysicsHandle || !HitResult.GetActor()) { return; }
	UE_LOG(LogTemp, Warning, TEXT("Grab")); // Test
	//Set Actor Rotation before Grabbing
	ComponentToGrab->GetRelativeRotation() = FRotator(0.f, 0.f, 0.f);
	//Grab 
	PhysicsHandle->GrabComponentAtLocationWithRotation
	(
		HitResult.GetComponent(),
		NAME_None,
		ComponentToGrab->GetRelativeLocation(),
		ComponentToGrab->GetRelativeRotation()
	);
	PhysicsHandle2->SetInterpolationSpeed(20.f);
}
void UGrabbar::Release()
{
	if (!PhysicsHandle) { UE_LOG(LogTemp, Error, TEXT("[Release] PhysicsHandle Not Set"));  return; }
	UE_LOG(LogTemp, Warning, TEXT("Release"));
	PhysicsHandle->ReleaseComponent();
}
void UGrabbar::Grab_FlashLight()
{
	//Get First Hit 
	FHitResult HitResult = LineTracing_FlashLight();
	UPrimitiveComponent* ComponentToGrab = HitResult.GetComponent();
	//Check
	if (!PhysicsHandle2 || !HitResult.GetActor() || !HitResult.GetActor()->ActorHasTag("FlashLight")) { return; }
	UE_LOG(LogTemp, Warning, TEXT("Grab_FlashLight"));
	//Set Actor Rotation before Grabbing
	ComponentToGrab->SetRelativeRotation(FRotator(0.f, 0.f, 0.f));
	//Grab 
	PhysicsHandle2->GrabComponentAtLocationWithRotation
	(
		ComponentToGrab,
		NAME_None,
		ComponentToGrab->GetRelativeLocation(),
		ComponentToGrab->GetRelativeRotation()
	);
	PhysicsHandle2->SetInterpolationSpeed(20.f);
}
void UGrabbar::Release_FlashLight()
{
	if (!PhysicsHandle2) { UE_LOG(LogTemp, Error, TEXT("[Release_FlashLight] PhysicsHandle2 Not Set")); return; }
	UE_LOG(LogTemp, Warning, TEXT("Release_FlashLight"));
	PhysicsHandle2->ReleaseComponent();
}
void UGrabbar::TurnOnLight()
{
	UE_LOG(LogTemp, Error, TEXT("TurnOnLight"));
	if (!SpotLight) { return; }
	SpotLight->SetVisibility(true);
}
void UGrabbar::TurnOffLight()
{
	UE_LOG(LogTemp, Error, TEXT("TurnOffLight"));
	if (!SpotLight) { return; }
	SpotLight->SetVisibility(false);
}
void UGrabbar::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
	//Check
	if (!PhysicsHandle || !PhysicsHandle2) { return; }
	//Get
	FRotator TargetRotation = PlayerRotation();
	//[PhysicsHandle] Get Grabbed Component then Set Target Location And Rotation
	if (PhysicsHandle->GetGrabbedComponent())
	{
		FVector  TargetLocation = TraceEnd(true, 75.f, -45.f, 0.f, 45.f); //true means CustomRange. false DefaultRange
		PhysicsHandle->SetTargetLocationAndRotation(TargetLocation, TargetRotation);
	}
	//[PhysicsHandle2] Get Grabbed Component then Set Target Location And Rotation
	if (PhysicsHandle2->GetGrabbedComponent())
	{
		FVector  TargetLocation = TraceEnd(true, 75.f, 45.f, 0.f, 45.f); //true means CustomRange. false DefaultRange
		TargetRotation.Pitch += 180.f;
		PhysicsHandle2->SetTargetLocationAndRotation(TargetLocation, TargetRotation);
		UE_LOG(LogTemp, Warning, TEXT("TargetLocation: %s || TargetRotation: %s"), *TargetLocation.ToString(), *TargetRotation.ToString());
	}

}
FHitResult UGrabbar::LineTracing_FlashLight()
{
	FHitResult H_FlashLight;
	FCollisionQueryParams Params(FName(""), false, GetOwner());
	//Ray-Cast
	bool b_HitResult = GetWorld()->LineTraceSingleByObjectType
	(
		H_FlashLight,
		PlayerLocation(),
		TraceEnd(false),
		FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
		Params
	);
	//Check
	if (b_HitResult && H_FlashLight.GetActor()->ActorHasTag("FlashLight"))
	{
		SpotLight = H_FlashLight.GetActor()->FindComponentByClass<USpotLightComponent>();// SpotLight Component
		UE_LOG(LogTemp, Warning, TEXT("[LineTracing_FlashLight] It's a flash light || Name: %s"), *H_FlashLight.GetActor()->GetName());
		return H_FlashLight;
	}
	else if (b_HitResult && H_FlashLight.GetActor())
	{
		UE_LOG(LogTemp, Error, TEXT("[LineTracing_FlashLight] It's not a flash light || Name: %s"), *H_FlashLight.GetActor()->GetName());
	}
	else
	{
		UE_LOG(LogTemp, Error, TEXT("[LineTracing_FlashLight] It's not a flash light"));
	}
	return H_FlashLight;
}
FHitResult UGrabbar::LineTracing_Other()
{
	FHitResult H_ToGrab;
	FCollisionQueryParams Params(FName(""), false, GetOwner());
	//Ray-Cast
	bool b_ToGrab = GetWorld()->LineTraceSingleByObjectType
	(
		H_ToGrab,
		PlayerLocation(),
		TraceEnd(false),
		ECollisionChannel::ECC_PhysicsBody,
		Params
	);
	//Check
	if (b_ToGrab)
	{
		if (!H_ToGrab.GetActor()->ActorHasTag("FlashLight"))
		{
			UE_LOG(LogTemp, Warning, TEXT("[ LineTracing_Other ] The name of Holding Object: %s"), *H_ToGrab.GetActor()->GetName());
		}
	}
	return H_ToGrab;
}
FVector UGrabbar::TraceEnd(bool CustomRange, float p_Range, float Dir, float Roll, float Pitch)
{
	FRotator Rotation = PlayerRotation();
	if (Dir ==  0.f)
	{
		if (Roll == 0.f)
		{
			if (!CustomRange)
			{
				
				return  PlayerLocation() + Rotation.Vector() * DefaultRange;
			}
			else
			{
				
				return  PlayerLocation() + Rotation.Vector() * p_Range;
			}
		}
		else
		{
			if (!CustomRange)
			{
				Rotation.Roll += Roll;
				return  PlayerLocation() + Rotation.Vector() * DefaultRange;
			}
			else
			{
				Rotation.Roll += Roll;
				return  PlayerLocation() + Rotation.Vector() * p_Range;
			}
		}

	}
	else
	{
		if (Roll == 0.f)
		{
			Rotation.Yaw += Dir;

			if (!CustomRange)
			{
				return  PlayerLocation() + Rotation.Vector() * DefaultRange;
			}
			else
			{
				return  PlayerLocation() + Rotation.Vector() * p_Range;
			}
		}
		else
		{
			Rotation.Yaw += Dir;
			Rotation.Roll += Roll;
			if (!CustomRange)
			{
				return  PlayerLocation() + Rotation.Vector() * DefaultRange;
			}
			else
			{
				return  PlayerLocation() + Rotation.Vector() * p_Range;
			}
		}
	}
}
FVector UGrabbar::PlayerLocation()
{
	FVector PlayerLocation;
	FRotator PlayerRotation;
	GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(PlayerLocation, PlayerRotation);
	return PlayerLocation;
}
FRotator UGrabbar::PlayerRotation()
{
	FVector PlayerLocation;
	FRotator PlayerRotation;
	GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(PlayerLocation, PlayerRotation);
	return PlayerRotation;
}
void UGrabbar::AddNewComp()
{
	PhysicsHandle2 = NewObject<UPhysicsHandleComponent>(this, "PhysicsHandle2");
	if (PhysicsHandle2)
	{
		UE_LOG(LogTemp, Warning, TEXT("PhysicsHandle2 != Nullptr"));
		PhysicsHandle2->RegisterComponent();
		GetOwner()->AddInstanceComponent(PhysicsHandle2);
	}
	else
	{
		UE_LOG(LogTemp, Error, TEXT("PhysicsHandle2 = Nullptr"));
	}
	GetOwner()->GetComponents(Components);
}

3 Likes

Privacy & Terms