• 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Yalcin2 · Jun 14, 2018 at 08:10 PM · multiplayerunity 2dphotonmultiplayer-networkingunity multiplayer

Unity Photon how to show arm/gun movement with mouse to other players.,Unity Photon: How to show arm movement to other players

I am currently trying to make a multiplayer game to further my knowledge on C#. When I join the game/room, my player`s gun, which is stuck to the player, is rotating with the mouse as an input. The problem is showing the other players on the photon network the gun rotation of my player.

Script (attached to the player`s gun):

 public PlayerMove playerMove;
 Vector3 difference;

 // Update is called once per frame
 void Update () {

     if (playerMove.photonView.isMine)
     {
         RotateArm();
     }
     else
     {

     }
 }

 private void RotateArm()
 {
     difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
     difference.Normalize();

     float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
     Quaternion rotation = Quaternion.AngleAxis(rotZ , Vector3.forward);
     transform.rotation = Quaternion.Slerp(transform.rotation, rotation, 5f * Time.deltaTime);
 }

I cannot figure out and understand what I need to put inside the else statement inside the update... Any help would be appreciated thanks :)

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Yalcin2 · Jun 15, 2018 at 02:09 PM

UPDATE: I managed to fix my problem by adding a script which streams and receives the gun`s rotation from the client player to the other players.

 public PlayerMove playerMove;
 private int rotationOffset = 0;
 private Quaternion gunPos;
 private Vector3 difference;

 // Update is called once per frame
 void Update () {
     if (playerMove.photonView.isMine)
     {
         RotateArm();
     }
     else
     {
         SmoothNetMovement();
     }

 }

 private void RotateArm()
 {
     difference = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
     difference.Normalize();

     float rotZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
     transform.rotation = Quaternion.Euler(0f, 0f, rotZ + rotationOffset);
     //Quaternion rotation = Quaternion.AngleAxis(rotZ , Vector3.forward);
     //transform.rotation = Quaternion.Slerp(transform.rotation, rotation, 5f * Time.deltaTime);
 }

 private void SmoothNetMovement()
 {
     transform.rotation = Quaternion.Lerp(transform.rotation, gunPos, Time.deltaTime * 8);
 }

 private void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     if (stream.isWriting)
     {
         stream.SendNext(transform.rotation);
     }
     else
     {
         gunPos = (Quaternion)stream.ReceiveNext();
     }
 }
Comment
Add comment · Share
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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

212 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 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

Raycast over Photon 0 Answers

[PHOTON] Transform not synching correctly 0 Answers

Multiplayer FPS Gun Position - Local vs Networked Client 1 Answer

Build errors when using Photon 2 ,Build errors after using Photon 0 Answers

How do I sync Rigidbody2D over the network? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges