PDA

View Full Version : Problems with sharing a camera, part 2



lethil
07-04-2011, 04:03 AM
Howdy!

I'm so close to having my basic control scheme set up for my proof of concept, but I've run into an issue. All local players should share the same camera instance.

Currently, Player 1's camera is what shows on the screen, but each PlayerController has their own camera. The problem with that is that player movement is relative to the camera, so each player is not moving consistently.

I attempted to fix this by creating a camera variable in my GameInfo and set each player to that camera, but they still don't seem to share the same camera.

Here's the code for my attempt:



class DareGame extends UDKGame
config(Game);

var DarePlayerCamera DareCam;

event PostLogin( PlayerController NewPlayer )
{
super.PostLogin(NewPlayer);
NewPlayer.ClientMessage("You're logged in as: "$NewPlayer.PlayerReplicationInfo.PlayerName);
}

event PlayerController Login(string Portal, string Options, const UniqueNetID UniqueID, out string ErrorMessage)
{
local PlayerController PC;
PC = super.Login(Portal, Options, UniqueID, ErrorMessage);
PC.PlayerCamera = DareCam;
ChangeName(PC, "DarePlayer", true);
if ( bDelayedStart )
{
PC.ServerRestartPlayer();
}

return PC;
}

event InitGame (string Options, out string ErrorMessage)
{
DareCam = Spawn(class'Dare.DarePlayerCamera');
super.InitGame(Options, ErrorMessage);
}

defaultproperties
{
PlayerControllerClass=class'Dare.DarePlayerControl ler'
DefaultPawnClass=class'Dare.DarePawn'
bDelayedStart=false
bRestartLevel=false
}


As always, any help would be appreciated!

Jason

lethil
07-04-2011, 04:32 AM
Wow, talk about answering my own questions...

I figured a way to do this (though let me know if this is a horrible idea).

Instead of making a shared camera, I made a shared rotator. All of my camera work references this centralized rotator now, so now everything is sharing this one rotation and all control use is relative to it.

Woo hoo!

lethil
07-05-2011, 06:03 PM
As expected, I've run into potential issues about everyone sharing a single PC's camera.

Is there a way to programmatically create a camera that all PC's share?

Any help is appreciated!

lethil
07-05-2011, 08:27 PM
I'm _sorta_ further now.

I've been able to get all of the players to start with a camera that I initialize on my GameInfo class, but after the "Unreal" movie plays in "UDKGame" mode, the game crashes. I presume it's because the camera isn't completely initialized. Is there something I need to programmatically do to the camera that a PlayerController does by default to get it to connect to the Viewport correctly?

Object
07-05-2011, 08:43 PM
well idk about the camera being initialized, but if ure doing a multiplayer game, gameinfo only exists on the server

lethil
07-05-2011, 08:46 PM
Good to know. :)

I haven't even gotten to the network multiplayer game aspect, so that won't be great.

What sort of class would be recommended for shared game data, such as a shared camera orientation between all players?

Object
07-05-2011, 08:51 PM
i would create my own camera manager class that is replicated to the clients from the server's gameinfo. It would store a reference to it in the playercontrollers

lethil
07-05-2011, 08:53 PM
CameraManager, eh? This seems to be a class I haven't heard of. Sounds like some more digging is in store.

Object
07-05-2011, 10:13 PM
ah sorry, i seemed to have mislead u. i meant that i would create a new class from object and use it to manage the camera via a couple of functions that replicate the camera object.

heres a better method.

create the camera in the gameinfo. then replicate it to a reference in all the player controllers. then adjust every tick

lethil
07-05-2011, 10:20 PM
I tried that, but unfortunately it crashed the game. If you have any tips on that, it'd be appreciated. :)