Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Wesley21spelde · Feb 11, 2018 at 06:18 PM · rigidbodyphotonviewinstatiate

Spawn Gameobject over all Clients and server not working

Hey guys i am trying to get my photon view to instantiate my bullet over the photon network but i dont know how to Get this rigidbody bullet to spwan over the network when my rpc is called

[PunRPC] public void Spartan_Pistol_Fire() { {

     int state = Random.Range(0, 2);

     if (state == 1)
         MuzzleFlash.GetComponent<MeshRenderer>().enabled = false;
     else
         MuzzleFlash.GetComponent<MeshRenderer>().enabled = true;
     // Invoke("Fire1", m_TimeOut);

     Rigidbody instantiatedProjectile = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
     instantiatedProjectile.velocity = transform.TransformDirection(new Vector3(0, 0, speed));
 }

 if (isShooting == false)
 {
     MuzzleFlash.GetComponent<MeshRenderer>().enabled = false;
 }

   
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ChristianSimon · Feb 13, 2018 at 10:44 AM 0
Share

Hi,

this seems to be okay so far. Can you confirm that the function gets called on each client who is connected to the same room? What parameters do you use when invoking the RPC call on the PhotonView component?

avatar image Wesley21spelde ChristianSimon · Feb 13, 2018 at 10:57 AM 0
Share

Hi i am using this . im not shure if this is what you mean.

 if (Input.GetButtonDown("Fire1"))
             photonView.RPC("Spartan_Pistol_Fire", PhotonTargets.All);

at my end of the game it fires my gun. but on the other clienets nothing happend

by the way here is the full script

  public float speed = 200;
     public float fireRate = 1;
     public bool isShooting = false;
     public float flickerRate = .3f;
     Vector3 realPosition = Vector3.zero;
     Quaternion realRotation = Quaternion.identity;
 
 
     void Start()
     {
         if (isShooting == false)
             $$anonymous$$uzzleFlash.GetComponent<$$anonymous$$eshRenderer>().enabled = false;
         InvokeRepeating("$$anonymous$$uzzleFlashRender", .1f, flickerRate);
 
     }
 
     // Update is called once per frame
     void Update()
     {
         if (Input.GetButtonDown("Fire1"))
             photonView.RPC("Spartan_Pistol_Fire", PhotonTargets.All);
        // Send$$anonymous$$essage("Fire1");
         
 
        //
     }
 
     void $$anonymous$$uzzleFlashRender ()
     {
         int state = Random.Range(0, 2);
 
         if (state == 1)
             $$anonymous$$uzzleFlash.GetComponent<$$anonymous$$eshRenderer>().enabled = false;
         else
             $$anonymous$$uzzleFlash.GetComponent<$$anonymous$$eshRenderer>().enabled = true;
     }
     [PunRPC]
     public void Spartan_Pistol_Fire()
     {
         {
 
             int state = Random.Range(0, 2);
 
             if (state == 1)
                 $$anonymous$$uzzleFlash.GetComponent<$$anonymous$$eshRenderer>().enabled = false;
             else
                 $$anonymous$$uzzleFlash.GetComponent<$$anonymous$$eshRenderer>().enabled = true;
             // Invoke("Fire1", m_TimeOut);
 
             GameObject clone = (GameObject)PhotonNetwork.Instantiate("Bullet", transform.position, transform.rotation);
             clone.GetComponent<Rigidbody>().velocity = Vector3.forward * speed;
 
             // Rigidbody instantiatedProjectile = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
             //instantiatedProjectile.velocity = transform.TransformDirection(new Vector3(0, 0, speed));
         }
 
         if (isShooting == false)
         {
             $$anonymous$$uzzleFlash.GetComponent<$$anonymous$$eshRenderer>().enabled = false;
         }
     }
 }
avatar image ChristianSimon Wesley21spelde · Feb 13, 2018 at 02:06 PM 0
Share

You should add a if (!photonView.is$$anonymous$$ine) { return; } at the beginning of the Update function to make sure, that only the owner of the object is allowed to fire the weapon.

In the RPC function itself you have a Random.Range call. Please note that this call can have different results on each client. In your case you might have the result, that one client enables the $$anonymous$$eshRenderer but nobody else. So your game might run out of synchronization here.

Besides that instantiating the bullet should work. If it isn't visible after checking and applying above mentioned fixes, please try Debug.Log on the remote client and check if the RPC is executed at all.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

156 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Photon Weapon View 1 Answer

Photon Player Weapon View Error Help Please 1 Answer

Instatiate help 1 Answer

Photon Weapon synchronize View Help Please 0 Answers

Network Rigidbodies act weird? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges