Download

Local Multiplayer (No Networking) Camera

Alright, so I did some intensive searching before posting this thread, as it could be a complicated question. I haven’t the foggiest idea where to start.

  • Our game is a 2D fighting game, that can have up to 4 potential players. This is based upon a combination of how many controllers there are and selection at the character select screen.
  • This is (not at the moment) at networked game, I am addressing the issue of a fully local (1PC) multi controller fighting game.

We started with the Paper2D C++ template, and so far it has brought us a considerable way. Massive Kudos to the Unreal team for including that. It saved us allot of research time, and allowed us to dive right into the engine. On to the issue:

We need a camera similar to Smash Bros, where the camera will expand and shrink taking all 4 players (or less) into account.

Issue #1: RESOLVED
I’ve stripped out most of the original template stuff with no problem, the only bit left is the camera code. <- For some reason, I tried it again after cleaning out the ‘Intermediate’ folder and it compiled after removing this code.


// Create a camera boom attached to the root (capsule)
		CameraBoom = PCIP.CreateDefaultSubobject<USpringArmComponent>(this, TEXT("CameraBoom"));
		CameraBoom->AttachTo(RootComponent);
		CameraBoom->TargetArmLength = 200.0f;
		CameraBoom->SocketOffset = FVector(0.0f, 0.0f, 0.0f);
		CameraBoom->bAbsoluteRotation = true;
		CameraBoom->RelativeRotation = FRotator(0.0f, -90.0f, 0.0f);

		SideViewCameraComponent = PCIP.CreateDefaultSubobject<UCameraComponent>(this, TEXT("SideViewCamera"));
		SideViewCameraComponent->ProjectionMode = ECameraProjectionMode::Perspective;
		SideViewCameraComponent->OrthoWidth = 2048.0f;
		SideViewCameraComponent->AttachTo(CameraBoom, USpringArmComponent::SocketName);

		// Prevent all automatic rotation behavior on the camera, character, and camera component
		CameraBoom->bAbsoluteRotation = true;
		SideViewCameraComponent->bUsePawnControlRotation = false;

When I try to remove it, the editor just flat out crashes on compile. I removed all references to this camera in the headers, and in the base character code. It persist to crash my editor.

Issue #2:
How would I go about having a camera detect all 4 players and reference their position? I don’t mind completely writing the camera in the blueprint editor and making a copy for each stage. I assume I can’t be attaching a new camera component to each player, as is done by default in the base character code now.

Issue #3:
How do I even handle mutliplayer? I’ve searched and searched on this and keep finding information networked games. I’ve unticked the ‘Split Screen’ option, but am lost from that point on.

Issue #4:
I think this is probably a silly question, but I will ask anyhow. When handling multiplayer, I noticed the spawn points are already randomized, which is exactly what we wanted, however, we don’t want 2 players starting at the same spawn point, is there a flag to check if a spawn point is occupied? I assume this is along the lines of what I am looking for?
https://forums.unrealengine.com/showthread.php?2107-Come-Learn-Blueprint-Multiplayer-with-me!-(aka-Tom-s-a-Glutton-for-Punishment)&p=12895&viewfull=1#post12895

I think I am just going to use the tag field, and ‘mark’ a spawn point once a player has been initialized there.

This is a shot of what we’re working with:
lost_zps56772a48.png

Basically, I can use any information on setting up a local player game (no networking of any kind involved) using one or more controllers, and how to make them all use a single camera during a game mode via C++. I could also place the camera as a blueprint per level, and set it up that way. We are using a plugin for direct input controllers, but advice on standard controllers will work just as well.

Thanks again for helping out. It is very appreciated. We are transitioning our entire project from Game Maker and I haven’t used Unreal for game development since the old UDK, so any help is welcome.

I’ll try to give you some ideas to work on, as I had once to do that in UDK, and will have to dot it again with UE4.

What is the crash exactly? I guess there are references to SideViewCameraComponent which is not initialized anymore.

It shouldn’t be too hard to write a custom camera class which updates its position so that all players are visible all the time. You would have a blueprint camera, you could add as an actor in each level. (see after for more explanations)

I didn’t look at UE4’s code related to local multiplayer yet, but as far as I remember what I did in UDK, you have to add new player controllers to the game being played. To do so, you can have a look at the function CreateLocalPlayer on the class UGameInstance. I didn’t use it yet, but I guess that’s the correct starting point when you want local multiplayer.

Then, you will need one camera that all players will use, hence the camera actor I talked about before. To assign this camera to each player controller, there is the function APlayerController::SetViewTarget to which you give the instance of the camera of the level.

I would do that also.

Hope this helps :slight_smile:

That does a bit, that would make sense just to add more characters at runtime. Does this mean I want to delete out the default pawn line from my game mode?

I resolved the crash by deleting my ‘Intermediate’ folder.

I made a camera class, and then changed the parent of a camera blueprint to my new cpp camera class. The camera is still ‘there’ but has lost its camera component, despite the class being derived from a camera class.

.cpp
#include “SSPHeartsInIcePrivate.h”
#include “DefaultSmashCamera.h”

ADefaultSmashCamera::ADefaultSmashCamera(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{

}

.h
#pragma once

#include “Camera/PlayerCameraManager.h”
#include “DefaultSmashCamera.generated.h”

/**
*
*/
UCLASS()
class SSPHEARTSINICE_API ADefaultSmashCamera : public APlayerCameraManager
{
GENERATED_UCLASS_BODY()

};

Thanks for the quick response and friendly information!

Alright, I think I might have had a clever idea. I gathered the code I deleted from the pawn, and placed it on the camera component itself:

#include “SSPHeartsInIcePrivate.h”
#include “DefaultSmashCamera.h”

ADefaultSmashCamera::ADefaultSmashCamera(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
CameraBoom = PCIP.CreateDefaultSubobject<USpringArmComponent>(this, TEXT(“CameraBoom”));
CameraBoom->AttachTo(RootComponent);
CameraBoom->TargetArmLength = 200.0f;
CameraBoom->SocketOffset = FVector(0.0f, 0.0f, 0.0f);
CameraBoom->bAbsoluteRotation = true;
CameraBoom->RelativeRotation = FRotator(0.0f, -90.0f, 0.0f);

SideViewCameraComponent = PCIP.CreateDefaultSubobject&lt;UCameraComponent&gt;(this, TEXT("SideViewCamera"));
SideViewCameraComponent-&gt;ProjectionMode = ECameraProjectionMode::Perspective;
SideViewCameraComponent-&gt;OrthoWidth = 2048.0f;
SideViewCameraComponent-&gt;AttachTo(CameraBoom, USpringArmComponent::SocketName);

// Prevent all automatic rotation behavior on the camera, character, and camera component
CameraBoom-&gt;bAbsoluteRotation = true;
SideViewCameraComponent-&gt;bUsePawnControlRotation = false;

}

This returned my camera component to the blueprint, and retained some of the base settings. So now I just need to add the camera to the pawn via your code. Let me give that a test and I will report back.

This (the link above) didn’t help clear things up. When I defined it in the player’s header it say it was an illegal reference. However, the camera now exist from code, which is a big step forward.

For the fun of it, I shoved a blueprint on it:

camera.png

It doesn’t throw any errors, but no such luck.

AND… When I re-parent the camera to my camera class, the editor crashes. It worked a minute ago, and not it is crashing for no reason… I guess it is going to be completely programmed.

This is why I should sleep more, it should have been obvious why that blueprint above wasn’t going to work. I am going to forgo programming the camera with C++ and do it with a straight blueprint. I despise blueprints, but I need to learn them, and the person editing the level will be using them. So he needs full access to the camera.

https://answers.unrealengine.com/questions/13312/how-to-temporarily-change-player-camera-to-externa.html