Refactored TempCharacter code
This commit is contained in:
parent
2c7a717617
commit
f632a010a4
@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:f4a37ec4a9d65f2b21c7e29d31fb9b9dd998e181aa264ca826aa1e6594da30ef
|
||||
size 23329
|
||||
oid sha256:1ef2465e4c7f6a5910df3ec5a3923c9a0f80eb17ddb1411de806275274b50ba1
|
||||
size 24707
|
||||
|
@ -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;
|
||||
LineTraceLogic();
|
||||
}
|
||||
|
||||
void ATempCharacter::LineTraceLogic()
|
||||
{
|
||||
float GlobalTrace = TraceDistance;
|
||||
FHitResult OutHit;
|
||||
FVector Start = GetActorLocation();
|
||||
FVector End = Start + TraceDistance * GetActorForwardVector();
|
||||
FVector End = Start + GlobalTrace * GetActorForwardVector();
|
||||
|
||||
FCollisionQueryParams TraceParams;
|
||||
|
||||
TraceParams.AddIgnoredActor(this);
|
||||
|
||||
bool bHit = GetWorld()->LineTraceSingleByChannel(Hit,Start,End,ECC_Visibility, TraceParams);
|
||||
if(bHit)
|
||||
bool bHit = GetWorld()->LineTraceSingleByChannel(OutHit, Start, End, ECC_Visibility, TraceParams);
|
||||
if (bHit)
|
||||
{
|
||||
if(Hit.GetActor()->ActorHasTag("MerchantTag"))
|
||||
if (OutHit.GetActor()->ActorHasTag("MerchantTag"))
|
||||
{
|
||||
DrawDebugLine(GetWorld(),Start, End, FColor::Green, false, 1.0f);
|
||||
UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *Hit.GetActor()->GetName());
|
||||
DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 1.0f);
|
||||
UE_LOG(LogTemp, Display, TEXT("HIT: %s"), *OutHit.GetActor()->GetName());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user