- Home /
update AddForce though Network 5.2
Hello, I am trying to sync bullets and update the function Rigidbody.AddForce through the network in unity 5.2. All items have a their respective components (NetworkIdentities and Rigidbodies). Both the player and the bullet prefabs are in the NetworkManager. The outcome when I run it: in the client when I shoot, the force is added while in other clients, the bullet is only spawned. Could not find the answer anywhere else.
Code Below (this script is in the player object):
Answer by Chom1czek · Oct 20, 2015 at 11:53 AM
Haven't tried it on but I think it should work, worth a shot:
[Command]
void CmdShot()
{
your code but remove last part with rigidbody and add this line:
RpcAddForceOnAll(bullet);
}
[ClientRpc]
void RpcAddForceOnAll(GameObject bullet)
{
bullet.GetComponent<Rigidbody>().AddForce(stuff);
}
Good luck.
It did solve the problem and the Addforce was synched, but it did not work as I expected, since the force would be added initially and if the bullet was moved or affected after that, the position would obviously not update. I'll try to put a network transform in the bullet to see if that solves it.
Thanks for the answer though! It did help me progress =D.
Happy to help, I made my own question about it, is it legit way to do it, but still waiting. But if it works I think its a good way :)
Well, just to let you know and anyone else watching, after I added the network transform + your code, it worked perfectly. Thanks again =P.
Your answer
![](https://koobas.hobune.stream/wayback/20220612041419im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
uNet rigidbodies can't push each other 1 Answer
Unity networking tutorial? 6 Answers
Knockback in Networking 1 Answer
How do I Assign client authority to a gameobject? 1 Answer
Can I export a swf from Unity which is "local-with-filesystem"? 0 Answers