x


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.

more ▼

asked May 31 '11 at 07:23 AM

Vincent22 gravatar image

Vincent22
31 3 3 3

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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

more ▼

answered May 02 '12 at 08:53 PM

Matt- gravatar image

Matt-
63 2 2 5

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1670
x1253
x708
x681
x113

asked: May 31 '11 at 07:23 AM

Seen: 1147 times

Last Updated: May 02 '12 at 08:54 PM