Request for help with UNET bullet spawn issue

Hi,

I would like to ask for you input on the following issue.
I have multiplayer working (well game is work in progress!), the issue so far is that when bullets (in my case snowballs) are spawned (from client, you can see around 10 seconds into video) they seem to just roll on the floor not where the camera is pointing too, when the server player does this it works fine. I am relly confused about this behaviour!

See sample video:

My [Command] code:
[Command]
void CmdSpawnBall (){
GameObject throwB = Instantiate (Ball, this.transform.GetChild(0).transform.position + (this.transform.GetChild(0).transform.forward * 1.75f), this.transform.GetChild(0).transform.rotation) as GameObject;
NetworkServer.Spawn (throwB);
Rigidbody tmpRB = throwB.GetComponent ();
tmpRB.AddRelativeForce (new Vector3 (0, 0, throwforce));
}

I use this.transform.GetChild(0).transform to find my camera that is a child on the player object.
Does the code look ok?
Would appreciate any suggestions.

Where is throwforce set? Why does the server have the client’s camera?

Many thanks for your help/input.
throwforce is set in the same script (e.g. public float throwforce = 5500f;) , but the same behaviour is seen if I replace the variable name with 5500f…

For your other point “Why does the server have the client’s camera?”, I believe you might be referring too a intro camera, when you click join this camera is disabled, then the player is instantiated (via networkmanager) which has it’s own camera, so I do not believe the server has the clients camera. Also, the server is working the same way (but bullets work ok there).

Thanks, hopefully I have explained that enough, hoping you may have further ideas.

So here’s what I don’t understand then. You said “I use this.transform.GetChild(0).transform to find my camera that is a child on the player object”, but you’re calling that on the server, not the client. Are you sure on the server that GetChild(0) will find the correct active GameObject which represents the client’s camera? Because I suspect it does not. Might want to add a Debug.Log statement spitting out that child object’s name inside that Command.

Ok cool, thanks for your input, much appreciated. I might add a gameobject variable and place the correct camera/spawn point object in there, reference that.

So the camera object is on the server version, and in the correct position as on the client, but just disabled? If so, that might work. Otherwise you could just send the position/rotation when you call the Command.

I was able to get this resolved by adding a Network Transform child component and adding my camera as a target, debugging showed that the camera (of local player) was not rotation I as expected (on server)… not sure why but anyway it now works :slight_smile:
Thanks Joe-Censored for your input / help!
Now to get mesh deformation synced, nicely :slight_smile: