- Home /
Player Instantiate in online game
Hi everybody. I'm developing a simple multiplayer online game with Unity3d. I have a problem with player instantiate. For each player I network instantiate an empty game object prefab and I instantiate the character prefab and make it child of empty game object prefab (I use this method because I have some problem with character pivot and orientation). The problem is that players that are playing can see only the other empty object and not the other child object (the remote characters). How can I solve my problem? This is my code:
var respawn_x=Random.Range(-3134.925,-3473.049);
var respawn_z=Random.Range(645.9182,941.0953);
var respawn_y = 206.66;
var ObjectParent = Network.Instantiate(GameObjectVuoto, transform.position, transform.rotation,0);
charController = ObjectParent.GetComponent(CharacterController);
charController.radius = 15.04244;
charController.height = 38.8195;
pl = Network.Instantiate(characterPrefab, transform.position, transform.rotation,0);
pl.transform.parent = ObjectParent.transform;
ObjectParent.transform.position = Vector3(respawn_x,respawn_y,respawn_z);
pl.transform.Rotate(Vector3(0,355.5273,0));
I've tried making a network.instantiate also for the character prefab (attaching a network view) but it doesn't work.
Answer by Matt- · May 02, 2012 at 08:53 PM
Aside from the Network.Instantiate
calls, everything else is only being done LOCALLY. So the GameObjectVuoto
is being created for everyone, but the charController.radius
and charController.height
are not being set.
Similarly p1
gets created for every instance on the network but will only have its transform.parent
and position
set on the local side.
// this creates an instance of characterPrefab
// on EVERY connected computer
pl = Network.Instantiate(characterPrefab,transform.position,transform.rotation,0);
// this sets the parent of my LOCAL INSTANCE ONLY
// no changes are made on any other connected computer
pl.transform.parent = ObjectParent.transform;
To get this to work you'll have to move all of those updates into an RPC, and then call those RPCs to get the changes to be effected on every connected instance instead of just locally.
http://unity3d.com/support/documentation/Components/net-RPCDetails
Your answer
Follow this Question
Related Questions
Multiplayer Projectile Instantiation 1 Answer
How can I spawn a GameObject on all players in my multiplayer game? 0 Answers
How to close multiple GUI Buttons and open other gui buttons 1 Answer
Network.Instantiate instantiazing 2 prefabs 1 Answer
Network.Destroy doesn't remove objects on other systems? 2 Answers