void UCheatManager::ChangeSize( float F ) { APawn* Pawn = GetOuterAPlayerController()->GetPawn(); // Note: only works on characters ACharacter *Character = Cast<ACharacter>(Pawn); if (Character) { ACharacter* DefaultCharacter = Character->GetClass()->GetDefaultObject<ACharacter>(); Character->GetCapsuleComponent()->SetCapsuleSize(DefaultCharacter->GetCapsuleComponent()->GetUnscaledCapsuleRadius() * F, DefaultCharacter->GetCapsuleComponent()->GetUnscaledCapsuleHalfHeight() * F); if (Character->GetMesh()) { Character->GetMesh()->SetRelativeScale3D(FVector(F)); } Character->TeleportTo(Character->GetActorLocation(), Character->GetActorRotation()); } }
bool ALabyrinthGameMode::IsSpawnpointPreferred(APlayerStart* SpawnPoint, AController* Player) const { ACharacter* MyPawn = Cast<ACharacter>((*DefaultPawnClass)->GetDefaultObject<ACharacter>()); // TO-DO: Add AI Controller //ALAIController* AIController = Cast<ALAIController>(Player); /*if (AIController != nullptr) { MyPawn = Cast<ACharacter>(BotPawnClass->GetDefaultObject<ACharacter>()); }*/ if (MyPawn) { const FVector SpawnLocation = SpawnPoint->GetActorLocation(); for (FConstPawnIterator It = GetWorld()->GetPawnIterator(); It; It++) { ACharacter* OtherPawn = Cast<ACharacter>(*It); if (OtherPawn && OtherPawn != MyPawn) { const float CombinedHeight = (MyPawn->GetCapsuleComponent()->GetScaledCapsuleHalfHeight() + OtherPawn->GetCapsuleComponent()->GetScaledCapsuleHalfHeight()) * 2.0f; const float CombinedRadius = (MyPawn->GetCapsuleComponent()->GetScaledCapsuleRadius() + OtherPawn->GetCapsuleComponent()->GetScaledCapsuleRadius()); const FVector OtherLocation = OtherPawn->GetActorLocation(); // Check if the player start overlaps this pawn if (FMath::Abs(SpawnLocation.Z - OtherLocation.Z) < CombinedHeight && (SpawnLocation - OtherLocation).Size2D() < CombinedRadius) { return false; } } } } else { return false; } return true; }
AActor * AHunterProjectile::FindHitActor() { const FVector &thisLocation = GetActorLocation(); UFlockingDataCache *cache = UFlockingDataCache::GetCacheChecked(this); ACharacter *playerCharacter = nullptr; for (FConstControllerIterator It = GetWorld()->GetControllerIterator(); It; ++It) { AController *controller = *It; APawn *otherPawn = controller->GetPawn(); if (otherPawn == nullptr) { continue; } if (controller->IsA(APlayerController::StaticClass())) { playerCharacter = Cast<ACharacter>(controller->GetPawn()); } } const TArray<FVector> &calfLocations = cache->GetTeamData(TEAM_CALVES)->m_locations; const TArray<FVector> &playerLocations = cache->GetLocationsPlayer(); int32 targetCalf = FindHitActor(calfLocations, cache->GetTeamData(TEAM_CALVES)->m_agentRadius * 0.5f); AActor *targetActor = nullptr; if (targetCalf == INDEX_NONE) { int32 targetPlayer = FindHitActor(playerLocations, 0.5f * playerCharacter->GetCapsuleComponent()->GetScaledCapsuleRadius()); if (targetPlayer != INDEX_NONE) { targetActor = playerCharacter; } } else { targetActor = cache->GetOrCreateTeamData(TEAM_CALVES).m_agents[targetCalf]; } return targetActor; }
bool ASGameMode::IsSpawnpointPreferred(APlayerStart* SpawnPoint, AController* Controller) { if (SpawnPoint) { /* Iterate all pawns to check for collision overlaps with the spawn point */ const FVector SpawnLocation = SpawnPoint->GetActorLocation(); for (FConstPawnIterator It = GetWorld()->GetPawnIterator(); It; It++) { ACharacter* OtherPawn = Cast<ACharacter>(*It); if (OtherPawn) { const float CombinedHeight = (SpawnPoint->GetCapsuleComponent()->GetScaledCapsuleHalfHeight() + OtherPawn->GetCapsuleComponent()->GetScaledCapsuleHalfHeight()) * 2.0f; const float CombinedWidth = SpawnPoint->GetCapsuleComponent()->GetScaledCapsuleRadius() + OtherPawn->GetCapsuleComponent()->GetScaledCapsuleRadius(); const FVector OtherLocation = OtherPawn->GetActorLocation(); // Check if player overlaps the playerstart if (FMath::Abs(SpawnLocation.Z - OtherLocation.Z) < CombinedHeight && (SpawnLocation - OtherLocation).Size2D() < CombinedWidth) { return false; } } } /* Check if spawnpoint is exclusive to players */ ASPlayerStart* MyPlayerStart = Cast<ASPlayerStart>(SpawnPoint); if (MyPlayerStart) { return MyPlayerStart->GetIsPlayerOnly() && !Controller->PlayerState->bIsABot; } } return false; }