Skip to content

Commit

Permalink
Implemented FPSPlayerConroller for multiplayer mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Relrin committed Jan 7, 2018
1 parent 7fe7451 commit e4a82a5
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 8 deletions.
Binary file modified Content/Blueprints/BP_GameMode.uasset
Binary file not shown.
Binary file added Content/Blueprints/BP_PlayerController.uasset
Binary file not shown.
Binary file modified Content/Maps/FirstPersonExampleMap.umap
Binary file not shown.
Binary file modified Content/Maps/FirstPersonExampleMap_BuiltData.uasset
Binary file not shown.
10 changes: 7 additions & 3 deletions Source/FPSGame/Private/FPSGameMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ void AFPSGameMode::CompleteMission(APawn* InstigatorPawn, bool bMissionSuccess)
if (AvailableActors.Num() > 0)
{
AActor* SpectatingViewpoint = AvailableActors[0];
APlayerController* Controller = Cast<APlayerController>(InstigatorPawn->GetController());
if (Controller)

for (FConstPlayerControllerIterator It = GetWorld()->GetPlayerControllerIterator(); It; It++)
{
Controller->SetViewTargetWithBlend(SpectatingViewpoint, 0.5f, EViewTargetBlendFunction::VTBlend_Cubic);
APlayerController* Controller = It->Get();
if (Controller)
{
Controller->SetViewTargetWithBlend(SpectatingViewpoint, 0.5f, EViewTargetBlendFunction::VTBlend_Cubic);
}
}
}
}
Expand Down
17 changes: 12 additions & 5 deletions Source/FPSGame/Private/FPSGameState.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
// Fill out your copyright notice in the Description page of Project Settings.

#include "FPSGameState.h"
#include "FPSPlayerController.h"
#include "Engine/World.h"


void AFPSGameState::MulticastOnMissionComplete_Implementation(APawn* InstigatorPawn, bool bMissionSuccess)
{
for(FConstPawnIterator it = GetWorld()->GetPawnIterator(); it; it++)
for (FConstPlayerControllerIterator It = GetWorld()->GetPlayerControllerIterator(); It; It++)
{
APawn* Pawn = it->Get();
if (Pawn && Pawn->IsLocallyControlled())
AFPSPlayerController* PlayerController = Cast<AFPSPlayerController>(It->Get());
if (PlayerController && PlayerController->IsLocalController())
{
Pawn->DisableInput(nullptr);
PlayerController->OnMissionCompleted(InstigatorPawn, bMissionSuccess);

// Disable input
APawn* Pawn = PlayerController->GetPawn();
if (Pawn && Pawn->IsLocallyControlled())
{
Pawn->DisableInput(nullptr);
}
}
}
}

3 changes: 3 additions & 0 deletions Source/FPSGame/Private/FPSPlayerController.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Fill out your copyright notice in the Description page of Project Settings.

#include "FPSPlayerController.h"
20 changes: 20 additions & 0 deletions Source/FPSGame/Public/FPSPlayerController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "FPSPlayerController.generated.h"

/**
*
*/
UCLASS()
class FPSGAME_API AFPSPlayerController : public APlayerController
{
GENERATED_BODY()

public:
UFUNCTION(BlueprintImplementableEvent, Category = "PlayerController")
void OnMissionCompleted(APawn* InstigatorPawn, bool bMissionSuccess);
};

0 comments on commit e4a82a5

Please sign in to comment.