From f632a010a45c3bbfefa033f4e33c7a5f19f78bcf Mon Sep 17 00:00:00 2001 From: MH261677 Date: Fri, 11 Nov 2022 22:21:10 +0000 Subject: [PATCH] Refactored TempCharacter code --- Content/Levels/MerchantPrototype.umap | 4 +- .../PlayerTemp/TempCharacter.cpp | 52 ++++++++++--------- .../PlayerTemp/TempCharacter.h | 8 ++- 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/Content/Levels/MerchantPrototype.umap b/Content/Levels/MerchantPrototype.umap index caea42f..ae52d8b 100644 --- a/Content/Levels/MerchantPrototype.umap +++ b/Content/Levels/MerchantPrototype.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f4a37ec4a9d65f2b21c7e29d31fb9b9dd998e181aa264ca826aa1e6594da30ef -size 23329 +oid sha256:1ef2465e4c7f6a5910df3ec5a3923c9a0f80eb17ddb1411de806275274b50ba1 +size 24707 diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp index a2d2355..f5f9681 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.cpp @@ -6,7 +6,6 @@ #include "../../../Plugins/Developer/RiderLink/Source/RD/thirdparty/clsocket/src/ActiveSocket.h" - // CONSTRUCTOR ATempCharacter::ATempCharacter() { @@ -23,13 +22,13 @@ void ATempCharacter::BeginPlay() //Binds the input we made in the setup player component to the forward vector void ATempCharacter::ForwardInput(float Axis) { - AddMovementInput(GetActorForwardVector()* Axis); + AddMovementInput(GetActorForwardVector() * Axis); } //Binds the input we made in the setup player component to the right vector void ATempCharacter::RightMoveInput(float Axis) { - AddMovementInput(GetActorRightVector()* Axis); + AddMovementInput(GetActorRightVector() * Axis); } @@ -47,30 +46,33 @@ void ATempCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCompo PlayerInputComponent->BindAxis(TEXT("Move Right / Left"), this, &ATempCharacter::RightMoveInput); PlayerInputComponent->BindAxis(TEXT("Turn Right / Left Mouse"), this, &ATempCharacter::AddControllerYawInput); PlayerInputComponent->BindAxis(TEXT("Look Up / Down Mouse"), this, &ATempCharacter::AddControllerPitchInput); - PlayerInputComponent->BindAction("Interact", IE_Pressed, this, &ATempCharacter::KeyPressed); // custom keybind Interact + PlayerInputComponent->BindAction("Interact", IE_Pressed, this, &ATempCharacter::KeyPressed); + // custom keybind Interact } + void ATempCharacter::KeyPressed() { - //vars for LineTraceSingleByChannel - TraceDistance = 1000; - FHitResult Hit; - FVector Start = GetActorLocation(); - FVector End = Start + TraceDistance * GetActorForwardVector(); - - FCollisionQueryParams TraceParams; - - TraceParams.AddIgnoredActor(this); - - bool bHit = GetWorld()->LineTraceSingleByChannel(Hit,Start,End,ECC_Visibility, TraceParams); - if(bHit) - { - if(Hit.GetActor()->ActorHasTag("MerchantTag")) - { - DrawDebugLine(GetWorld(),Start, End, FColor::Green, false, 1.0f); - UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *Hit.GetActor()->GetName()); - } - } - + LineTraceLogic(); } - \ No newline at end of file +void ATempCharacter::LineTraceLogic() +{ + float GlobalTrace = TraceDistance; + FHitResult OutHit; + FVector Start = GetActorLocation(); + FVector End = Start + GlobalTrace * GetActorForwardVector(); + + FCollisionQueryParams TraceParams; + + TraceParams.AddIgnoredActor(this); + + bool bHit = GetWorld()->LineTraceSingleByChannel(OutHit, Start, End, ECC_Visibility, TraceParams); + if (bHit) + { + if (OutHit.GetActor()->ActorHasTag("MerchantTag")) + { + DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1.0f); + UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName()); + } + } +} diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h index 5545325..6843434 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h @@ -22,8 +22,6 @@ protected: void ForwardInput(float Axis); void RightMoveInput(float Axis); - float TraceDistance; - public: // Called every frame virtual void Tick(float DeltaTime) override; @@ -32,4 +30,10 @@ public: virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override; void KeyPressed(); + + UPROPERTY(EditAnyWhere) + float TraceDistance = 200; + + void LineTraceLogic(); + };