Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fill out your copyright notice in the Description page of Project Settings.
- #include "OdZera.h"
- #include "SUMPlayerController.h"
- #include "AI/Navigation/NavigationSystem.h"
- #include "SUMCharacter.h"
- ASUMPlayerController::ASUMPlayerController(const FObjectInitializer& ObjectInitializer)
- : Super(ObjectInitializer)
- {
- bShowMouseCursor = true;
- DefaultMouseCursor = EMouseCursor::Crosshairs;
- }
- void ASUMPlayerController::SetupInputComponent()
- {
- Super::SetupInputComponent();
- InputComponent->BindAction("SetDestination", IE_Pressed, this, &ASUMPlayerController::MoveToClickedPoint);
- InputComponent->BindAction("SwitchCameras", IE_Pressed, this, &ASUMPlayerController::SwitchCameras);
- }
- void ASUMPlayerController::PlayerTick(float DeltaTime)
- {
- Super::PlayerTick(DeltaTime);
- }
- void ASUMPlayerController::MoveToClickedPoint()
- {
- FHitResult Hit;
- GetHitResultUnderCursor(ECC_Visibility, false, Hit);
- if (Hit.bBlockingHit)
- {
- SetNewMoveDestination(Hit.ImpactPoint);
- }
- }
- void ASUMPlayerController::SwitchCameras()
- {
- APawn* const Pawn = GetPawn();
- if (Pawn)
- {
- ASUMCharacter* MyPawn = Cast<ASUMCharacter>(Pawn);
- if (MyPawn){
- MessageBoxA(0, "", "", 0);
- MyPawn->CameraBoom->RelativeRotation = FRotator(0.f, 0.0f, 0.f);
- }
- }
- }
- void ASUMPlayerController::SetNewMoveDestination(const FVector DestLocation)
- {
- APawn* const Pawn = GetPawn();
- if (Pawn)
- {
- UNavigationSystem* const NavSys = GetWorld()->GetNavigationSystem();
- float const Distance = FVector::Dist(DestLocation, Pawn->GetActorLocation());
- // We need to issue move command only if far enough in order for walk animation to play correctly
- if (NavSys && (Distance > 120.0f))
- {
- MessageBoxA(0, "", "", 0);
- NavSys->SimpleMoveToLocation(this, DestLocation);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement