void ACinemotusPlayerController::AbsoluteTick(float DeltaTime) { TotalYawAbs += addYaw; UPrimitiveComponent* prim = GetPawn()->GetMovementComponent()->UpdatedComponent; //USceneComponent* sComponent = GetPawn()->GetRootComponent(); //sComponent->SetRelativeLocation; bool SetPrimDirectly = true; FQuat finalQuat; if (((currentCaptureState&ECinemotusCaptureState::EAbsolute) == ECinemotusCaptureState::EAbsolute) && ((currentCaptureState&ECinemotusCaptureState::EAbsoluteOff) == 0)) { finalQuat = FRotator(0, TotalYawAbs, 0).Quaternion()*(HydraLatestData->controllers[CAM_HAND].quat); } else { finalQuat = FRotator(0, addYaw, 0).Quaternion()*prim->GetComponentQuat(); } SetControlRotation(finalQuat.Rotator()); if (SetPrimDirectly && prim) { prim->SetWorldLocationAndRotation(prim->GetComponentLocation(), finalQuat);// not sure need } HandleMovementAbs(DeltaTime, ((currentCaptureState&ECinemotusCaptureState::EAbsolute) == ECinemotusCaptureState::EAbsolute)); }
void AAIController::UpdateControlRotation(float DeltaTime, bool bUpdatePawn) { // Look toward focus FVector FocalPoint = GetFocalPoint(); APawn* const Pawn = GetPawn(); if (Pawn) { FVector Direction = FAISystem::IsValidLocation(FocalPoint) ? (FocalPoint - Pawn->GetPawnViewLocation()) : Pawn->GetActorForwardVector(); FRotator NewControlRotation = Direction.Rotation(); // Don't pitch view unless looking at another pawn if (Cast<APawn>(GetFocusActor()) == nullptr) { NewControlRotation.Pitch = 0.f; } NewControlRotation.Yaw = FRotator::ClampAxis(NewControlRotation.Yaw); if (GetControlRotation().Equals(NewControlRotation, 1e-3f) == false) { SetControlRotation(NewControlRotation); if (bUpdatePawn) { Pawn->FaceRotation(NewControlRotation, DeltaTime); } } } }
bool AMyAIController::FindClosestEnemy() { AMyChar* mySelf = Cast<AMyChar>(GetPawn()); if (!mySelf) return false; const FVector myLoc = mySelf->GetActorLocation(); float BestDistSq = MAX_FLT; AMyChar * bestTarget = nullptr; for (FConstPawnIterator iter = GetWorld()->GetPawnIterator(); iter; ++iter) { AMyChar* tmpTarget = Cast<AMyChar>(*iter); if (tmpTarget != mySelf) { if (tmpTarget) { const float DistSq = (tmpTarget->GetActorLocation() - myLoc).SizeSquared(); if (DistSq < BestDistSq) { BestDistSq = DistSq; bestTarget = tmpTarget; FString str = FString::Printf(TEXT("--- find enemy dist:%f"), BestDistSq); GEngine->AddOnScreenDebugMessage(0, 2.0f, FColor::Red, str); } } } } if (bestTarget) { return SetEnemy(bestTarget); } return false; }
void AFrisbeeNulPlayerController::releaseFrisbee() { this->frisbee->unattachToPlayer(); this->frisbee->mesh->SetPhysicsLinearVelocity(FVector(0, 0, 0)); this->frisbee->mesh->AddForce(GetPawn()->GetActorForwardVector() * 10000000); }
void AFrisbeeNulPlayerController::getFrisbee() { this->frisbee->attachToPlayer(GetPawn()); this->frisbee->SetActorRelativeLocation(FVector(0, 0, 230)); }
void AFrisbeeNulPlayerController::MoveRight(float AxisValue) { APawn* const Pawn = GetPawn(); if (Pawn && this->frisbee->playerOwner != Pawn) { Pawn->AddMovementInput(FVector::RightVector, FMath::Clamp<float>(AxisValue, -1.0f, 1.0f), false); } }
AMWWaypoint* AMWPatController::FindNearestWaypoint(bool bSetAsNext) { const AMWPat* pat = Cast<AMWPat>(GetPawn()); if (!pat) { return nullptr; } float minDist = MAX_FLT; AMWWaypoint* nearestWp = nullptr; // get all the waypoints in the level TArray<AActor*> foundActors; UGameplayStatics::GetAllActorsOfClass(this, AMWWaypoint::StaticClass(), foundActors); if (!foundActors.Num()) { UE_LOG(LogTemp, Error, TEXT("No waypoints in the level")); return nullptr; } for (AActor* actor : foundActors) { const float dist = (pat->GetActorLocation() - actor->GetActorLocation()).SizeSquared(); AMWWaypoint* waypoint = Cast<AMWWaypoint>(actor); const FString patTag = pat->WaypointTag; const FString wpTag = waypoint->Tag; // tags must match if (dist < minDist && patTag == wpTag) { minDist = dist; nearestWp = waypoint; } } if (!nearestWp) { UE_LOG(LogTemp, Error, TEXT("Pat %s couldn't find a waypoint with matching tag %s"), *pat->GetName(), *pat->WaypointTag); return nullptr; } // check whether we are already stand on that waypoint // normally waypoints stay far away from each other, so there is only one possible overlapping at a given time TArray<AActor*> overlaps; pat->GetOverlappingActors(overlaps, AMWWaypoint::StaticClass()); if (overlaps.Num() && overlaps[0] == nearestWp) { check(nearestWp->Next) nearestWp = nearestWp->Next; } if (nearestWp && bSetAsNext) { SetNextWaypoint(nearestWp); } return nearestWp; }
void ATankAIController::onPossedTankDeath() { UE_LOG(LogTemp, Warning, TEXT("%s Is Dead"), *GetPawn()->GetName()) possessedTank->DetachFromControllerPendingDestroy(); }
void ASoftDesignTrainingPlayerController::OnTakeCoverPressed() { APawn* const Pawn = GetPawn(); if (Pawn) { FVector actorLocation = Pawn->GetActorLocation(); FRotator actorRotation = Pawn->GetActorRotation(); FVector coverTestStart = actorLocation; FVector coverTestEnd = actorLocation + 400.0f * actorRotation.Vector(); UWorld* currentWorld = GetWorld(); static FName InitialCoverSweepTestName = TEXT("InitialCoverSweepTest"); FHitResult hitResult; FQuat shapeRot = FQuat::Identity; FCollisionShape collShape = FCollisionShape::MakeSphere(Pawn->GetSimpleCollisionRadius()); FCollisionQueryParams collQueryParams(InitialCoverSweepTestName, false, Pawn); currentWorld->DebugDrawTraceTag = InitialCoverSweepTestName; FCollisionObjectQueryParams collObjQueryParams(ECC_WorldStatic); UDesignTrainingMovementComponent* charMovement = Cast<UDesignTrainingMovementComponent>(Pawn->GetMovementComponent()); if (currentWorld->SweepSingleByObjectType(hitResult, coverTestStart, coverTestEnd, shapeRot, collObjQueryParams, collShape, collQueryParams)) { if (charMovement->ValidateCover(hitResult)) { MoveToCoverDestination(hitResult.Location); } } } }
void AAIController::UnPossess() { APawn* CurrentPawn = GetPawn(); Super::UnPossess(); if (PathFollowingComponent) { PathFollowingComponent->Cleanup(); } if (bStopAILogicOnUnposses) { if (BrainComponent) { BrainComponent->Cleanup(); } } if (CachedGameplayTasksComponent && (CachedGameplayTasksComponent->GetOwner() == CurrentPawn)) { CachedGameplayTasksComponent->OnClaimedResourcesChange.RemoveDynamic(this, &AAIController::OnGameplayTaskResourcesClaimed); CachedGameplayTasksComponent = nullptr; } OnUnpossess(CurrentPawn); }
bool UPawnAction_Repeat::PushSubAction() { if (ActionToRepeat == NULL) { Finish(EPawnActionResult::Failed); return false; } else if (RepeatsLeft == 0) { Finish(EPawnActionResult::Success); return true; } if (RepeatsLeft > 0) { --RepeatsLeft; } UPawnAction* ActionCopy = SubActionTriggeringPolicy == EPawnSubActionTriggeringPolicy::CopyBeforeTriggering ? Cast<UPawnAction>(StaticDuplicateObject(ActionToRepeat, this, NULL)) : ActionToRepeat; UE_VLOG(GetPawn(), LogPawnAction, Log, TEXT("%s> pushing repeted action %s %s, repeats left: %d") , *GetName(), SubActionTriggeringPolicy == EPawnSubActionTriggeringPolicy::CopyBeforeTriggering ? TEXT("copy") : TEXT("instance") , *GetNameSafe(ActionCopy), RepeatsLeft); check(ActionCopy); RecentActionCopy = ActionCopy; return PushChildAction(*ActionCopy); }
void AMyPlayerController::SetNewMoveDestination(const FVector DestLocation) { if (!bIsPaused) { AMyAnt* MyAnt = Cast<AMyAnt>(UGameplayStatics::GetPlayerCharacter(this, 0)); APawn* const Pawn = GetPawn(); if (Pawn) { /*MyAnt->SetActorLocation(FMath::Lerp(MyAnt->GetActorLocation(), FVector(DestinationLocation.X, DestinationLocation.Y, MyAnt->GetActorLocation().Z), ToLocationCounter),true); if (ToLocationCounter >= 1.0f) { MovingToLocation = false; ToLocationCounter = 0; }*/ 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)) { NavSys->SimpleMoveToLocation(this, DestLocation); } } } }
void AZanshinAIController::OnFire() { AZanshinBot* character = Cast<AZanshinBot>(GetPawn()); if (character) { character->OnFire(character->GetActorLocation(), character->GetActorRotation()); } }
FPathFollowingRequestResult AWalkerAIController::MoveTo( const FAIMoveRequest& MoveRequest, FNavPathSharedPtr* OutPath) { #ifdef CARLA_AI_WALKERS_EXTRA_LOG UE_LOG(LogCarla, Log, TEXT("Walker %s requested move from (%s) to (%s)"), *GetPawn()->GetName(), *GetPawn()->GetActorLocation().ToString(), *MoveRequest.GetGoalLocation().ToString()) ; #endif // CARLA_AI_WALKERS_EXTRA_LOG ChangeStatus(EWalkerStatus::Moving); return Super::MoveTo(MoveRequest, OutPath); }
void AMapPlayerController::CameraMoveRight(float d) { if (d != 0.0f) { GetPawn()->AddActorWorldOffset(FVector(0, CameraMoveDistance * d, 0)); } }
void ATankAIController::Tick(float DeltaSeconds) { Super::Tick(DeltaSeconds); auto aiTank = GetPawn(); auto playerTank = GetWorld()->GetFirstPlayerController()->GetPawn(); if (ensure(playerTank)) { // TODO Move towards the player MoveToActor(playerTank, acceptanceRadius); // TODO check radius is in cm // Aim towards the player auto aimComponent = aiTank->FindComponentByClass<UTankAimingComponent>(); aimComponent->AimAt(playerTank->GetActorLocation()); //GetPawn().reloadTimeInSeconds = 10; // Fire if ready if (aimComponent->GetFiringState() == EFiringStatus::Ready) { aimComponent->Fire(); //UE_LOG(LogTemp,Warning,TEXT("AI Tank Ready and Firing!")) } } }
void AAIController::Possess(APawn* InPawn) { Super::Possess(InPawn); if (!GetPawn()) { return; } // no point in doing navigation setup if pawn has no movement component const UPawnMovementComponent* MovementComp = InPawn->GetMovementComponent(); if (MovementComp != NULL) { UpdateNavigationComponents(); } if (PathFollowingComponent) { PathFollowingComponent->Initialize(); } if (bWantsPlayerState) { ChangeState(NAME_Playing); } OnPossess(InPawn); }
/** Function called to search for an enemy - parameter void: - returns: void */ void AEnemyController::SearchForEnemy() { APawn* MyEnemy = GetPawn(); if (MyEnemy == NULL) return; const FVector MyLoc = MyEnemy->GetActorLocation(); float BestDistSq = MAX_FLT; ATankCharacter* BestPawn = NULL; for (FConstPawnIterator It = GetWorld()->GetPawnIterator(); It; It++) { ATankCharacter* TestPawn = Cast<ATankCharacter>(*It); if (TestPawn) { const float DistSq = FVector::Dist(TestPawn->GetActorLocation(), MyLoc); bool canSee = LineOfSightTo(TestPawn); //choose the closest option to the AI that can be seen if (DistSq < BestDistSq && canSee) { BestDistSq = DistSq; BestPawn = TestPawn; } } } if (BestPawn) { GEngine->AddOnScreenDebugMessage(0, 1.0f, FColor::Green, BestPawn->GetName()); SetEnemy(BestPawn); } }
void ACinemotusPlayerController::OnSwichPawn(bool increase) { //Get Current Pawn's rotation? if (PawnsInScene.Num() < 1) { return; } FString numstr = FString::Printf(TEXT("%d"), PawnsInScene.Num()); GEngine->AddOnScreenDebugMessage(-1, .5f, FColor::Yellow, numstr); int startIndex = currentPawnIndex; do { if (increase) { currentPawnIndex = currentPawnIndex + 1 < PawnsInScene.Num() ? currentPawnIndex + 1 : 0; } else { currentPawnIndex = currentPawnIndex - 1 < 0 ? PawnsInScene.Num() - 1 : currentPawnIndex - 1; } } while (PawnsInScene[currentPawnIndex]->bHidden && currentPawnIndex != startIndex); //keep going till we find a non hidden one APawn* nextPawn = PawnsInScene[currentPawnIndex]; Possess(nextPawn); SetViewTargetWithBlend(nextPawn, 0.0f); possessedCinePawn = Cast<ACinemotusDefaultPawn>(nextPawn); //GET JOYSTICK DATA GetCineData(GetPawn()); }
void ACitizenAIController::SetCurrentPosition() { if (BlackboardComp) { BlackboardComp->SetValueAsVector(CurrentPositionName, GetPawn()->GetActorLocation()); } }
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 ATankPlayerController::BeginPlay() { Super::BeginPlay(); auto AimingComponent = GetPawn()->FindComponentByClass<UTankAimingComponent>(); if (!ensure(AimingComponent)) { return; } FoundAimingComponent(AimingComponent); }
void ACubeDeathController::TickActor(float DeltaTime, enum ELevelTick TickType, FActorTickFunction& ThisTickFunction) { Super::TickActor(DeltaTime, TickType, ThisTickFunction); if(waiting) { if(breakTimer >= 0) { breakTimer -= DeltaTime; } else { // Spawn the shockwave playerCube->OnDeath(explosionForce); //Tell the gamemode that we are dead if(GetWorld() != nullptr) { ACubeWarsGameMode* cwgm = GetWorld()->GetAuthGameMode<ACubeWarsGameMode>(); cwgm->playerDied(teamNumber); } //Destroy actor GetPawn()->Destroy(); } } }
bool UPawnAction_Sequence::Start() { bool bResult = Super::Start(); if (bResult) { UE_VLOG(GetPawn(), LogPawnAction, Log, TEXT("Starting sequence. Items:"), *GetName()); for (auto Action : ActionSequence) { UE_VLOG(GetPawn(), LogPawnAction, Log, TEXT(" %s"), *GetNameSafe(Action)); } bResult = PushNextActionCopy(); } return bResult; }
void ATankAIController::Tick(float deltaTime) { Super::Tick(deltaTime); auto playerTank = GetWorld()->GetFirstPlayerController()->GetPawn(); if (ensure(playerTank && GetPawn())) { MoveToActor(playerTank, acceptanceRadius); auto aimingComponent = GetPawn()->FindComponentByClass<UTankAimingComponent>(); aimingComponent->AimAt(playerTank->GetActorLocation()); if(aimingComponent->GetFiringStatus() == EFiringStatus::Locked) aimingComponent->Fire(); } }
void ACarController::RotateY(float axisValue) { APawnCar* car = Cast<APawnCar>(GetPawn()); if (car == nullptr) return; rotation.Roll = FMath::Clamp(axisValue, -1.0f, 1.0f); car->SetRotationDirection(rotation); }
void ACarController::Thrust(float value) { APawnCar* car = Cast<APawnCar>(GetPawn()); if (car == nullptr) return; if (value > 0) car->Thrust(value); }
void ASPlayerController::ServerSuicide_Implementation() { ASCharacter* MyPawn = Cast<ASCharacter>(GetPawn()); if (MyPawn && ((GetWorld()->TimeSeconds - MyPawn->CreationTime > 1) || (GetNetMode() == NM_Standalone))) { MyPawn->Suicide(); } }
void ATDownPlayerController::PrevWeapon() { ATDownCharacter* GetChar = Cast<ATDownCharacter>(GetPawn()); if (GetChar) { GetChar->PrevWeapon(); } }
void ACarController::MoveForward(float axisValue) { APawnCar* car = Cast<APawnCar>(GetPawn()); if (car == nullptr) return; direction.Y = FMath::Clamp(axisValue, -1.0f, 1.0f); car->SetDirection(direction); }