it works!
First, I started with an empty Blueprint project, created a game mode, keyboard mappings (ASDW), created a player character by adding CPP-Code and 8 cameras. I then attached all those cameras to the cpp-character. Also, each camera is assigned to a corresponding player. Player0 is auto possessed.
The movement handling is done in CPP like this:
AMyCPPCharacter::AMyCPPCharacter()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void AMyCPPCharacter::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AMyCPPCharacter::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
// Called to bind functionality to input
void AMyCPPCharacter::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
// set up gameplay key bindings
InputComponent->BindAxis(“MoveForward”, this, &AMyCPPCharacter::MoveForward);
InputComponent->BindAxis(“MoveRight”, this, &AMyCPPCharacter::MoveRight);
Super::SetupPlayerInputComponent(InputComponent);
}
void AMyCPPCharacter::MoveForward(float Value)
{
if ( (Controller != NULL) && (Value != 0.0f) )
{
// find out which way is forward
FRotator Rotation = Controller->GetControlRotation();
// Limit pitch when walking or falling
if (GetCharacterMovement()->IsMovingOnGround() || GetCharacterMovement()->IsFalling() )
{
Rotation.Pitch = 0.0f;
}
// add movement in that direction
const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::X);
AddMovementInput(Direction, Value);
}
}
void AMyCPPCharacter::MoveRight(float Value)
{
if ( (Controller != NULL) && (Value != 0.0f) )
{
// find out which way is right
const FRotator Rotation = Controller->GetControlRotation();
const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::Y);
// add movement in that direction
AddMovementInput(Direction, Value);
}
}
The result looks like this:
I can control the player in the top left window and the movement is shown in all the other windows. I did not even need to iterate over the actors and propagate the movement.
As always…, once you have figured it out it’s actually very easy to do!
And the performance is quite good compared to the screenshot method.
What’s left to do is creating a beautiful maze and maybe also a beautiful landscape.
In retrospect, I find this way to be quite elegant. I am very happy with this solution!
UE4 is epic!