synchronize the rotation

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

synchronize the rotation

chucky831
2020-03-02 10:27:29

Hi everyone, I'm starting with Photon. I wanted to understand how I can synchronize a rotation. In my game I have 2 players who rotate their weapon in the direction of the mouse. This is the code I made for the single player. I should do a PUN function for rotation so that each player sees where the other is pointing. How should i do?

    void Update()  
    {  
        mousePos = Camera.main.ScreenToViewportPoint(Input.mousePosition);  
        posScreen = Camera.main.WorldToViewportPoint(gunPivot.position);  
        mousePos.z = 0;  
          
        Vector3 dir2 = (posScreen - mousePos).normalized;  
        gunPivot.rotation = Quaternion.LookRotation(Vector3.forward, mousePos - posScreen) * Quaternion.Euler(0,0,90);  
        Debug.DrawRay(gunPivot.position, dir2 * 10, Color.red);  
    }  

Comments

S_Oliver
2020-03-02 11:17:12

Just slam a PhotonView and TransformView on your Weapon gameObject.

https://doc.photonengine.com/en-us/pun/v2/demos-and-tutorials/pun-basics-tutorial/player-networking

chucky831
2020-03-02 16:33:19

but and is the child of an object that moves I have to apply the photon view to both the player and the child?

Back to top