Updated Interaction.cpp
Optimized some functions and variables by storing them in beginplay
This commit is contained in:
		
							parent
							
								
									b9d87ee07b
								
							
						
					
					
						commit
						3f4cdf5bfa
					
				@ -1,3 +1,3 @@
 | 
				
			|||||||
version https://git-lfs.github.com/spec/v1
 | 
					version https://git-lfs.github.com/spec/v1
 | 
				
			||||||
oid sha256:ebb8b1c4142831775542c0bcb3400dc138a3360ffe820dd74cd460af4b914a53
 | 
					oid sha256:5efb970894cb114a37a45fac46558718d0fa4bfed2b9900eebd2a752fc71d021
 | 
				
			||||||
size 26504
 | 
					size 26607
 | 
				
			||||||
 | 
				
			|||||||
@ -22,7 +22,10 @@ AInteraction::AInteraction()
 | 
				
			|||||||
void AInteraction::BeginPlay()
 | 
					void AInteraction::BeginPlay()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	Super::BeginPlay();
 | 
						Super::BeginPlay();
 | 
				
			||||||
	
 | 
						TempCharacter = GetWorld()->GetFirstPlayerController()->GetCharacter();
 | 
				
			||||||
 | 
						MainCamera = Cast<UCameraComponent>(TempCharacter->FindComponentByClass<UCameraComponent>());
 | 
				
			||||||
 | 
						TargetHealingLocation = HealingItem->GetActorLocation();
 | 
				
			||||||
 | 
						TargetBuffLocation = BuffItem->GetActorLocation();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Called every frame
 | 
					// Called every frame
 | 
				
			||||||
@ -80,8 +83,6 @@ void AInteraction::RemoveWidget()
 | 
				
			|||||||
void AInteraction::CameraLeftMover()
 | 
					void AInteraction::CameraLeftMover()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	UE_LOG(LogTemp, Display, TEXT("Button Left is being pressed"));
 | 
						UE_LOG(LogTemp, Display, TEXT("Button Left is being pressed"));
 | 
				
			||||||
	TempCharacter = GetWorld()->GetFirstPlayerController()->GetCharacter();
 | 
					 | 
				
			||||||
	MainCamera = Cast<UCameraComponent>(TempCharacter->FindComponentByClass<UCameraComponent>());
 | 
					 | 
				
			||||||
	if (TempCharacter == nullptr)
 | 
						if (TempCharacter == nullptr)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		UE_LOG(LogTemp, Display, TEXT("Character not found in Interaction.cpp"));
 | 
							UE_LOG(LogTemp, Display, TEXT("Character not found in Interaction.cpp"));
 | 
				
			||||||
@ -90,16 +91,15 @@ void AInteraction::CameraLeftMover()
 | 
				
			|||||||
	else
 | 
						else
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		UE_LOG(LogTemp, Display, TEXT("Character Found in interaction.cpp"));
 | 
							UE_LOG(LogTemp, Display, TEXT("Character Found in interaction.cpp"));
 | 
				
			||||||
		if (MainCamera == nullptr)
 | 
							if (MainCamera == nullptr || HealingItem == nullptr)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			UE_LOG(LogTemp, Display, TEXT("Camera not found in Interaction.cpp"));
 | 
								UE_LOG(LogTemp, Display, TEXT("Camera not found in Interaction.cpp"));
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			FVector TargetLocation = FVector(5700,-1270,4040);
 | 
								CameraLocation = MainCamera->GetComponentLocation();
 | 
				
			||||||
			FVector CameraLocation = MainCamera->GetComponentLocation();
 | 
								FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetHealingLocation);
 | 
				
			||||||
			FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetLocation);
 | 
					 | 
				
			||||||
			MainCamera->SetWorldRotation(CameraRotation);
 | 
								MainCamera->SetWorldRotation(CameraRotation);
 | 
				
			||||||
			MainCamera->SetFieldOfView(40);
 | 
								MainCamera->SetFieldOfView(40);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -109,8 +109,6 @@ void AInteraction::CameraLeftMover()
 | 
				
			|||||||
void AInteraction::CameraRightMover()
 | 
					void AInteraction::CameraRightMover()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	UE_LOG(LogTemp, Display, TEXT("Button Right is being pressed"));
 | 
						UE_LOG(LogTemp, Display, TEXT("Button Right is being pressed"));
 | 
				
			||||||
	TempCharacter = GetWorld()->GetFirstPlayerController()->GetCharacter();
 | 
					 | 
				
			||||||
	MainCamera = Cast<UCameraComponent>(TempCharacter->FindComponentByClass<UCameraComponent>());
 | 
					 | 
				
			||||||
	if (TempCharacter == nullptr)
 | 
						if (TempCharacter == nullptr)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		UE_LOG(LogTemp, Display, TEXT("Character not found in Interaction.cpp"));
 | 
							UE_LOG(LogTemp, Display, TEXT("Character not found in Interaction.cpp"));
 | 
				
			||||||
@ -119,16 +117,15 @@ void AInteraction::CameraRightMover()
 | 
				
			|||||||
	else
 | 
						else
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		UE_LOG(LogTemp, Display, TEXT("Character Found in interaction.cpp"));
 | 
							UE_LOG(LogTemp, Display, TEXT("Character Found in interaction.cpp"));
 | 
				
			||||||
		if (MainCamera == nullptr)
 | 
							if (MainCamera == nullptr || BuffItem == nullptr)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			UE_LOG(LogTemp, Display, TEXT("Camera not found in Interaction.cpp"));
 | 
								UE_LOG(LogTemp, Display, TEXT("Camera not found in Interaction.cpp"));
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			FVector TargetLocation = FVector(5260, -840, 4070);
 | 
								CameraLocation = MainCamera->GetComponentLocation();
 | 
				
			||||||
			FVector CameraLocation = MainCamera->GetComponentLocation();
 | 
								FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetBuffLocation);
 | 
				
			||||||
			FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetLocation);
 | 
					 | 
				
			||||||
			MainCamera->SetWorldRotation(CameraRotation);
 | 
								MainCamera->SetWorldRotation(CameraRotation);
 | 
				
			||||||
			MainCamera->SetFieldOfView(40);
 | 
								MainCamera->SetFieldOfView(40);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -24,10 +24,10 @@ public:
 | 
				
			|||||||
	// Called every frame
 | 
						// Called every frame
 | 
				
			||||||
	virtual void Tick(float DeltaTime) override;
 | 
						virtual void Tick(float DeltaTime) override;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	UPROPERTY(EditAnywhere)
 | 
						UPROPERTY(EditAnywhere, Category= "Widgets")
 | 
				
			||||||
	TSubclassOf<UUserWidget> ShopDialog;
 | 
						TSubclassOf<UUserWidget> ShopDialog;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	UPROPERTY(EditAnywhere)
 | 
						UPROPERTY(EditAnywhere, Category= "Widgets")
 | 
				
			||||||
	TSubclassOf<UUserWidget> ItemSelector;
 | 
						TSubclassOf<UUserWidget> ItemSelector;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	virtual void OnInteract();
 | 
						virtual void OnInteract();
 | 
				
			||||||
@ -40,7 +40,7 @@ public:
 | 
				
			|||||||
	UPROPERTY()
 | 
						UPROPERTY()
 | 
				
			||||||
	UUserWidget* ItemSelectorWidget;
 | 
						UUserWidget* ItemSelectorWidget;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	UPROPERTY(EditAnywhere)
 | 
						UPROPERTY(EditAnywhere, Category= "Widgets")
 | 
				
			||||||
	float WaitTimer = 8.0f;
 | 
						float WaitTimer = 8.0f;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	UPROPERTY()
 | 
						UPROPERTY()
 | 
				
			||||||
@ -60,5 +60,17 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player")
 | 
						UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player")
 | 
				
			||||||
	ACharacter* TempCharacter;
 | 
						ACharacter* TempCharacter;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Items")
 | 
				
			||||||
 | 
						AActor* HealingItem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Items")
 | 
				
			||||||
 | 
						AActor* BuffItem;
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					private:
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						FVector TargetHealingLocation;
 | 
				
			||||||
 | 
						FVector TargetBuffLocation;
 | 
				
			||||||
 | 
						FVector CameraLocation;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -43,6 +43,8 @@ public:
 | 
				
			|||||||
	void InputDisabler();
 | 
						void InputDisabler();
 | 
				
			||||||
	void LineTraceLogic();
 | 
						void LineTraceLogic();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	UPROPERTY(BlueprintReadWrite, EditAnywhere, Category= "Health")
 | 
						UPROPERTY(BlueprintReadWrite, EditAnywhere, Category= "Health")
 | 
				
			||||||
	float Health;
 | 
						float Health;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user