I just purchased the “Ultimate FPS Camera” (herein called UFPSC) from the asset store and I am now attempting to insert it into my previous project, a networked unity game.
For some reason, when I attempt to spawn the new FPSPlayer prefab from UFPSC, they are not syncing over the network as my old player prefab (with its simple and less awesome control scheme) would. Before I explain further, here is my Javascript (or Unityscript) code:
#pragma strict
//----------------------------------------------
// Instantiates a new player in the game
//----------------------------------------------
var fpsPrefab:GameObject;
var boxPrefab:GameObject;
function Start()
{
// The server tells the clients where to spawn
if( Network.isServer )
{
// Server spawns himself
var fpsObj:GameObject = GameObject.Instantiate( fpsPrefab, GetSpawnPoint(), Quaternion.identity );
var boxObj:GameObject = Network.Instantiate( boxPrefab, fpsObj.transform.position, fpsObj.transform.rotation, 0 );
boxObj.transform.parent = fpsObj.transform;
// Spawn the other players
for( var player:NetworkPlayer in Network.connections )
{
networkView.RPC( "OnSpawnPlayer", player, GetSpawnPoint() );
}
}
}
// Called when the client player spawns(the server is controlling who spawns where/when)
@RPC
function OnSpawnPlayer( spawnPoint:Vector3 )
{
var fpsObj:GameObject = GameObject.Instantiate( fpsPrefab, spawnPoint, Quaternion.identity );
var boxObj:GameObject = Network.Instantiate( boxPrefab, fpsObj.transform.position, fpsObj.transform.rotation, 0 );
boxObj.transform.parent = fpsObj.transform;
}
The two variables at the top, fpsPrefab and boxPrefab, are prefabs I dragged in using the editor. fpsPrefab is the “FPSPlayer” prefab from UFPSC and boxPrefab is a cube acting as an art placeholder (later, this will be the animated humanoid other clients will view). GetSpawnPoint() just returns a suitable spawn. I have a Network View component added to the Box prefab as well.
Although this Box prefab correctly instantiates on all clients/server and correctly follows the FPSPlayer object around on the client’s end, it won’t sync on the network to the other players (they just see a still box). Anyone know why this could be? Been fumbling for a few hours now…
My only idea is that perhaps it is because the other clients on the network don’t know that the Box object was made to be a child of the FPSPlayer object? I don’t know why that would effect it however because the Box object’s transform is still changing on each client…
Any help is greatly appreciated, thank you!
EDIT (more info):
OK, something very strange now. I wrote a separate script that tells the Box object to translate on the x axis by 1 if you press the space bar, and THAT works… But when I attempt to move it according to the FPSPlayer’s position, it won’t sync.
OK, hopefully the last edit. But it appears that the Network View is syncing using the Box object’s position relative to the FPSPlayer object (it’s local position). How can I get it to send the world position, or absolute position?