Advertisement
Guest User

Untitled

a guest
May 4th, 2015
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3. #include "OdZera.h"
  4. #include "SUMPlayerController.h"
  5. #include "AI/Navigation/NavigationSystem.h"
  6. #include "SUMCharacter.h"
  7.  
  8. ASUMPlayerController::ASUMPlayerController(const FObjectInitializer& ObjectInitializer)
  9.     : Super(ObjectInitializer)
  10. {
  11.     bShowMouseCursor = true;
  12.     DefaultMouseCursor = EMouseCursor::Crosshairs;
  13. }
  14.  
  15. void ASUMPlayerController::SetupInputComponent()
  16. {
  17.     Super::SetupInputComponent();
  18.     InputComponent->BindAction("SetDestination", IE_Pressed, this, &ASUMPlayerController::MoveToClickedPoint);
  19.     InputComponent->BindAction("SwitchCameras", IE_Pressed, this, &ASUMPlayerController::SwitchCameras);
  20.  
  21. }
  22.  
  23. void ASUMPlayerController::PlayerTick(float DeltaTime)
  24. {
  25.     Super::PlayerTick(DeltaTime);
  26.  
  27. }
  28.  
  29. void ASUMPlayerController::MoveToClickedPoint()
  30. {
  31.     FHitResult Hit;
  32.     GetHitResultUnderCursor(ECC_Visibility, false, Hit);
  33.     if (Hit.bBlockingHit)
  34.     {
  35.         SetNewMoveDestination(Hit.ImpactPoint);
  36.     }
  37. }
  38.  
  39. void ASUMPlayerController::SwitchCameras()
  40. {
  41.     APawn* const Pawn = GetPawn();
  42.     if (Pawn)
  43.     {
  44.         ASUMCharacter* MyPawn = Cast<ASUMCharacter>(Pawn);
  45.         if (MyPawn){
  46.             MessageBoxA(0, "", "", 0);
  47.             MyPawn->CameraBoom->RelativeRotation = FRotator(0.f, 0.0f, 0.f);
  48.         }
  49.     }
  50. }
  51.  
  52. void ASUMPlayerController::SetNewMoveDestination(const FVector DestLocation)
  53. {
  54.     APawn* const Pawn = GetPawn();
  55.     if (Pawn)
  56.     {
  57.         UNavigationSystem* const NavSys = GetWorld()->GetNavigationSystem();
  58.         float const Distance = FVector::Dist(DestLocation, Pawn->GetActorLocation());
  59.         // We need to issue move command only if far enough in order for walk animation to play correctly
  60.         if (NavSys && (Distance > 120.0f))
  61.         {
  62.             MessageBoxA(0, "", "", 0);
  63.             NavSys->SimpleMoveToLocation(this, DestLocation);
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement