- Home /
Add force to bullet in the network
Hi, I have a problem with the AddForce method:
When a player fire I istantiate an object called proiettile withi this code:
proiettile = PhotonNetwork.Instantiate(proiettilePrefab, muzzleFlash.transform.position, muzzleFlash.transform.rotation, 0) as GameObject;
Then I add force to it:
proiettile.rigidbody.AddForce(-transform.forward * 10000);
In the local player (the one that fire) bullets have force, but the other player sees only the istantiated bullets with no force that fall on the ground.
I added a PhotonView to the bullet prefab that observe the rigidbody of the bullet, but nothing happens.
Regards,
Marco
Answer by asafsitner · Dec 29, 2011 at 09:59 AM
What you want to do instead of having the player script add force to the bullet, is have the bullet propel itself.
Give the bullet the force at Start()
so when it instantiates it will propel forward everywhere.
$$anonymous$$y pleasure. Networking can cause some serious headache sometimes. :)
Answer by jorgon · Mar 14, 2012 at 11:57 AM
But I can't make that the projectile can be launched in the right direction if I turn my head...How can I attatch properly the launching of my projectiles to the direction where I'm looking at?.
I am having this exact same problem. I have tried countless things and cant get the projectile to travel in the direction of the head. I still don't know how to fix it!
Answer by marf · Mar 14, 2012 at 03:16 PM
I think that you should work with the projectile as a child of the player.
Your answer
Follow this Question
Related Questions
Instantiated over the client side by a photonviewed object? 1 Answer
Help with PUN PhotonNetworkView stuff. 1 Answer
Bullet on network 1 Answer
Matchmaking multiplayer help 0 Answers
RPC and inheritance 1 Answer