PlayerController cleanup
This commit is contained in:
@@ -17,9 +17,6 @@ DEFINE_LOG_CATEGORY(LogTemplateCharacter);
|
|||||||
ATerraformingAnubisPlayerController::ATerraformingAnubisPlayerController()
|
ATerraformingAnubisPlayerController::ATerraformingAnubisPlayerController()
|
||||||
{
|
{
|
||||||
bShowMouseCursor = true;
|
bShowMouseCursor = true;
|
||||||
DefaultMouseCursor = EMouseCursor::Default;
|
|
||||||
CachedDestination = FVector::ZeroVector;
|
|
||||||
FollowTime = 0.f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATerraformingAnubisPlayerController::BeginPlay()
|
void ATerraformingAnubisPlayerController::BeginPlay()
|
||||||
@@ -43,10 +40,7 @@ void ATerraformingAnubisPlayerController::SetupInputComponent()
|
|||||||
if (UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(InputComponent))
|
if (UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(InputComponent))
|
||||||
{
|
{
|
||||||
// Setup mouse input events
|
// Setup mouse input events
|
||||||
EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Started, this, &ATerraformingAnubisPlayerController::OnInputStarted);
|
EnhancedInputComponent->BindAction(ClickAction, ETriggerEvent::Started, this, &ATerraformingAnubisPlayerController::OnClick);
|
||||||
EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Triggered, this, &ATerraformingAnubisPlayerController::OnSetDestinationTriggered);
|
|
||||||
EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Completed, this, &ATerraformingAnubisPlayerController::OnSetDestinationReleased);
|
|
||||||
EnhancedInputComponent->BindAction(SetDestinationClickAction, ETriggerEvent::Canceled, this, &ATerraformingAnubisPlayerController::OnSetDestinationReleased);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -54,46 +48,7 @@ void ATerraformingAnubisPlayerController::SetupInputComponent()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ATerraformingAnubisPlayerController::OnInputStarted()
|
void ATerraformingAnubisPlayerController::OnClick()
|
||||||
{
|
{
|
||||||
StopMovement();
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
// Triggered every frame when the input is held down
|
|
||||||
void ATerraformingAnubisPlayerController::OnSetDestinationTriggered()
|
|
||||||
{
|
|
||||||
// We flag that the input is being pressed
|
|
||||||
FollowTime += GetWorld()->GetDeltaSeconds();
|
|
||||||
|
|
||||||
// We look for the location in the world where the player has pressed the input
|
|
||||||
FHitResult Hit;
|
|
||||||
bool bHitSuccessful = false;
|
|
||||||
bHitSuccessful = GetHitResultUnderCursor(ECollisionChannel::ECC_Visibility, true, Hit);
|
|
||||||
|
|
||||||
// If we hit a surface, cache the location
|
|
||||||
if (bHitSuccessful)
|
|
||||||
{
|
|
||||||
CachedDestination = Hit.Location;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move towards mouse pointer or touch
|
|
||||||
APawn* ControlledPawn = GetPawn();
|
|
||||||
if (ControlledPawn != nullptr)
|
|
||||||
{
|
|
||||||
FVector WorldDirection = (CachedDestination - ControlledPawn->GetActorLocation()).GetSafeNormal();
|
|
||||||
ControlledPawn->AddMovementInput(WorldDirection, 1.0, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ATerraformingAnubisPlayerController::OnSetDestinationReleased()
|
|
||||||
{
|
|
||||||
// If it was a short press
|
|
||||||
if (FollowTime <= ShortPressThreshold)
|
|
||||||
{
|
|
||||||
// We move there and spawn some particles
|
|
||||||
UAIBlueprintHelperLibrary::SimpleMoveToLocation(this, CachedDestination);
|
|
||||||
UNiagaraFunctionLibrary::SpawnSystemAtLocation(this, FXCursor, CachedDestination, FRotator::ZeroRotator, FVector(1.f, 1.f, 1.f), true, true, ENCPoolMethod::None, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
FollowTime = 0.f;
|
|
||||||
}
|
|
||||||
@@ -22,40 +22,22 @@ class ATerraformingAnubisPlayerController : public APlayerController
|
|||||||
public:
|
public:
|
||||||
ATerraformingAnubisPlayerController();
|
ATerraformingAnubisPlayerController();
|
||||||
|
|
||||||
/** Time Threshold to know if it was a short press */
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input)
|
|
||||||
float ShortPressThreshold;
|
|
||||||
|
|
||||||
/** FX Class that we will spawn when clicking */
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input)
|
|
||||||
UNiagaraSystem* FXCursor;
|
|
||||||
|
|
||||||
/** MappingContext */
|
/** MappingContext */
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true"))
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true"))
|
||||||
UInputMappingContext* DefaultMappingContext;
|
UInputMappingContext* DefaultMappingContext;
|
||||||
|
|
||||||
/** Jump Input Action */
|
/** Jump Input Action */
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true"))
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true"))
|
||||||
UInputAction* SetDestinationClickAction;
|
UInputAction* ClickAction;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** True if the controlled character should navigate to the mouse cursor. */
|
|
||||||
uint32 bMoveToMouseCursor : 1;
|
|
||||||
|
|
||||||
virtual void SetupInputComponent() override;
|
virtual void SetupInputComponent() override;
|
||||||
|
|
||||||
// To add mapping context
|
// To add mapping context
|
||||||
virtual void BeginPlay();
|
virtual void BeginPlay();
|
||||||
|
|
||||||
/** Input handlers for SetDestination action. */
|
|
||||||
void OnInputStarted();
|
|
||||||
void OnSetDestinationTriggered();
|
|
||||||
void OnSetDestinationReleased();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FVector CachedDestination;
|
void OnClick();
|
||||||
|
|
||||||
float FollowTime; // For how long it has been pressed
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user