void AMainPlayerController::ChooseTargetUnderMouseCursor() { /*if (clickedPawn != nullptr) { delete clickedPawn; clickedPawn = nullptr; }*/ // Trace to see what is under the mouse cursor FHitResult Hit; GetHitResultUnderCursor(ECC_Pawn, false, Hit); if (Hit.bBlockingHit) { //GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Magenta, Hit.GetActor()->GetName()); IGlobalMapInterface * mapObj = Cast<IGlobalMapInterface>(Hit.GetActor()); clickedPawn = Cast<ABasicCharacter>(Hit.GetActor()); if (mapObj != nullptr) { mapObj->showObjectInformation(); } /*if (clickedPawn == nullptr) { Cast<IGlobalMapInterface>(Hit.GetActor())->showObjectInformation(); }*/ } }
void AMouseController::PlayerTick(float DeltaTime) { Super::PlayerTick(DeltaTime); FHitResult hit; auto gameMode = Cast<AProjectTapGameMode>(GetWorld()->GetAuthGameMode()); //cast a ray for every 1/10 of a second if (raycastElapseTimeCounter < raycastElapseTime) { raycastElapseTimeCounter += DeltaTime; raycasted = false; } else { raycastElapseTimeCounter = 0.0f; raycasted = true; GetHitResultUnderCursor(ECC_Visibility, false, hit); } if (raycasted) { FVector origin; FVector direction; GetCameraRay(origin, direction); btManager.SetCameraRay(hit, origin, direction); checkObjectHighlight(hit); } if (bCheckForSwipe) { SendGroupedBlockingTile(hit); } btManager.Tick(DeltaTime); }
void AMouseController::NotifyMousePressed() { FHitResult hit; GetHitResultUnderCursor(ECC_Visibility, false, hit); ActivateOtherTiles(hit); EnableSwipeCheck(hit); }
void ATopDown_HitmanCleanPlayerController::MoveToMouseCursor(){ // Trace to see what is under the mouse cursor FHitResult Hit; GetHitResultUnderCursor(ECC_Visibility, false, Hit); if (Hit.bBlockingHit){ // We hit something, move there SetNewMoveDestination(Hit.ImpactPoint); } }
void ATDownPlayerController::OnActionPressed() { ATDownCharacter* GetChar = Cast<ATDownCharacter>(GetPawn()); if (GetChar) { FHitResult Hit; GetHitResultUnderCursor(ECC_GameTraceChannel1, false, Hit); GetChar->FireWeapon(Hit.ImpactPoint); } }
void APuzzlePresetPlayerController::OnTakeStonePressed() { // Trace to see what is under the mouse cursor FHitResult Hit; GetHitResultUnderCursor(ECC_Visibility, false, Hit); movedStone = Cast<APuzzlePresetBlock>(Hit.GetActor()); if (Hit.bBlockingHit && movedStone != nullptr) { movedStone->SetIsDragged(true); } }
void AMainPlayerController::MoveToMouseCursor() { FHitResult Hit; GetHitResultUnderCursor(ECC_Visibility, false, Hit); if (Hit.bBlockingHit) { /*if (targetPoint != nullptr) { delete targetPoint; }*/ GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Magenta, Hit.ImpactPoint.ToString()); if (clickedPawn != nullptr) { clickedPawn->targetPoint = Hit.ImpactPoint; } } }
void ALMPlayerController::PawnRotationToTarget() { if (this->bIsRotationChange) { FHitResult CursorHitRes = FHitResult(); if (GetHitResultUnderCursor(ECollisionChannel::ECC_Visibility, false, CursorHitRes)) { FVector FaceDir = CursorHitRes.Location - GetPawn()->GetActorLocation(); FRotator FaceRotator = FaceDir.Rotation(); FaceRotator.Pitch = 0; FaceRotator.Roll = 0; GetPawn()->SetActorRotation(FaceRotator); } } }
void ABaleroPlayerController::OnRightClickPressed() { UE_LOG(LogTemp, Warning, TEXT("rightclick")); FHitResult Hit; GetHitResultUnderCursor(ECC_Visibility, false, Hit); FVector2D MouseLocation; GetMousePosition(MouseLocation.X, MouseLocation.Y); int32 ViewportX; int32 ViewportY; GetViewportSize(ViewportX, ViewportY); if (MouseLocation.X > ViewportX * .9f) { return; } if (Hit.bBlockingHit) { UE_LOG(LogTemp, Warning, TEXT("rightclickedsomething")); APawn* pawn = Cast<APawn>(Hit.GetActor()); if (pawn != NULL) { UE_LOG(LogTemp, Warning, TEXT("clicked pawn")); ABaleroCharacter* Unit = Cast<ABaleroCharacter>(pawn); if (Unit != NULL) { MoveToActor(Unit); } } else { MoveToMouseCursor(); } } }
void AMyPlayerController::MoveToMouseCursor() { if (!bIsPaused) { // Trace to see what is under the mouse cursor FHitResult Hit; GetHitResultUnderCursor(ECC_Visibility, false, Hit); APawn* const Pawn = GetPawn(); //float const Distance = FVector::Dist(DestinationLocation, Pawn->GetActorLocation()); if (Hit.bBlockingHit) { DestinationLocation = Hit.ImpactPoint; // We hit something, move there SetNewMoveDestination(DestinationLocation); MovingToLocation = true; } } }
void ABaleroPlayerController::OnIncreaseSelectionPressed() { UE_LOG(LogTemp, Warning, TEXT("shiftclickpressed")); FHitResult Hit; GetHitResultUnderCursor(ECC_Visibility, false, Hit); if (Hit.bBlockingHit) { APawn* pawn = Cast<APawn>(Hit.Actor.Get()); if (pawn != NULL) { ABaleroCharacter* Unit = Cast<ABaleroCharacter>(pawn); if (Unit != NULL) { SelectedUnits.Add(Unit); Unit->SelectedEffect->SetVisibility(true); } } } }
void AZombieShooterPlayerController::PlayerTick(float DeltaTime) { Super::PlayerTick(DeltaTime); FHitResult Hit; GetHitResultUnderCursor(ECC_Visibility, false, Hit); if (ControlledPawn) { FVector WorldLocation, WorldDirection; DeprojectMousePositionToWorld(WorldLocation, WorldDirection); ControlledPawn->WorldLocation = WorldLocation; ControlledPawn->WorldDirection = WorldDirection; } float MouseX = 0.0f, MouseY = 0.0f; GetMousePosition(MouseX, MouseY); if (bRotating) { RotateCameraRight((MouseX - LastMouseX) * CameraSensitivity); LastMouseX = MouseX; } }
void ABaleroPlayerController::OnClickPressed() { UE_LOG(LogTemp, Warning, TEXT("clickpressed")); FHitResult Hit; GetHitResultUnderCursor(ECC_Visibility, false, Hit); FVector2D MouseLocation; GetMousePosition(MouseLocation.X, MouseLocation.Y); int32 ViewportX; int32 ViewportY; GetViewportSize(ViewportX, ViewportY); if (MouseLocation.X > ViewportX * .9f) { return; } if (Hit.bBlockingHit) { UE_LOG(LogTemp, Warning, TEXT("clickedsomething")); APawn* pawn = Cast<APawn>(Hit.GetActor()); if (pawn != NULL) { UE_LOG(LogTemp, Warning, TEXT("clicked pawn")); ABaleroCharacter* Unit = Cast<ABaleroCharacter>(pawn); if (Unit != NULL) { //deselect the clicked unit if (SelectedUnits.Contains(Unit)) { RemoveUnitFromSelection(Unit); } //add unit to selection else { AddUnitToSelection(Unit); } } } else { //give move command to move UE_LOG(LogTemp, Warning, TEXT("MOVE COMMAND_A")); for (ABaleroCharacter* Unit : SelectedUnits) { AAIControllerBase* AIControl = Cast<AAIControllerBase>(Unit->GetController()); FVector loc = Unit->GetActorLocation(); UE_LOG(LogTemp, Warning, TEXT("Unit ai: %s , pos: %.1f %.1f %.1f"), *(AActor::GetDebugName(AIControl)), loc.X, loc.Y, loc.Z); } MoveToMouseCursor(); } } else { UE_LOG(LogTemp, Warning, TEXT("MOVE COMMAND_B")); MoveToMouseCursor(); } }
void ATwinStickShooterPlayerController::LookAtMouseCursor() { ATwinStickShooterCharacter* const MyPawn = (ATwinStickShooterCharacter*)GetPawn(); if (MyPawn) { // Trace to see what is under the mouse cursor FHitResult Hit; GetHitResultUnderCursor(ECC_Visibility, false, Hit); //Gets player rotation FRotator PlayerRot = MyPawn->GetActorRotation(); //Gets the Directional Vector Ranging from -1 to 1 FVector PlayerDirection = PlayerRot.Vector()*-1; //Get The right vector for your character FRotator PlayerRightRot = PlayerDirection.Rotation(); PlayerRightRot.Add(0, 90, 0); FVector RightVector = PlayerRightRot.Vector(); //Gets the players current location minus the Z FVector PlayerLoc = MyPawn->GetActorLocation() * FVector(1, 1, 0); //Gets Mouse location minus the Z FVector MouseLoc = Hit.ImpactPoint * FVector(1, 1, 0); //Find the Desired angle of rotation between the Player and Mouse FRotator PlayerDesiredRot = (PlayerLoc - MouseLoc).Rotation(); //float FaceToAngle = PlayerDesiredRot.Clamp().Yaw; //Gets a Directional Vector Ranging from -1 to 1 in screenspace for the mouse from the character FVector MouseDirection = PlayerDesiredRot.Vector(); //The Aim at angle for the character MyPawn->AimAtAngle = ((acosf(FVector::DotProduct(PlayerDirection, MouseDirection))) * (180 / 3.1415926)); //Calculate the distances from all angles float RDist = FVector::Dist(MouseDirection, RightVector); float LDist = FVector::Dist(MouseDirection, RightVector*-1); float FDist = FVector::Dist(MouseDirection, PlayerDirection); float BDist = FVector::Dist(MouseDirection, PlayerDirection * -1); //Set bools if (RDist <= LDist) { MyPawn->bLookRight = true; } else { MyPawn->bLookRight = false; } if (FDist <= BDist) { MyPawn->bLookForward = true; } else { MyPawn->bLookForward = false; } //GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::Printf(TEXT("Aim Right : %d :: Aim Forward : %d ::"), bLookRight, bLookForward)); } }