Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
1
Question by Silsor · May 07, 2018 at 02:58 PM · multiplayervrphotonsynchronizationinteraction

Photon Objects interaction

Hello. I'm using Photon to make a multiplayer VR game. First player is on Oculus and the second is on vive. When I move object by first player (master) its barely ok. It doesn't synchronize when Im holding object, but when i drop it, it's in the correct position for both players. Player who joined to the server can move object like first (no synchronization while moving) but when i drop Object more than half Meter from its parent position its localPosition changes on (0,0,0). This is my Script:

 public void grabbedBy (Transform grabber)
 {
         
     Debug.Log(grabber.parent.name);
     //if (photonView.owner == PhotonNetwork.player)
     {
         transform.SetParent(grabber);
     }
     grabbed = true;
     _grabber = grabber.gameObject;
     GetComponent<Rigidbody>().useGravity = false;
     GetComponent<Rigidbody>().isKinematic = true;
 }

 public void realesedBy(Transform grabber, Vector3 linearVelocity, Vector3 angularVelocity)
 {
     Rigidbody rigidbody = GetComponent<Rigidbody>();
     
     grabbed = false;
     //rigidbody.useGravity = true;
     //rigidbody.velocity = linearVelocity;
     //rigidbody.angularVelocity = angularVelocity;
     //GetComponent<Rigidbody>().useGravity = true;
     GetComponent<Rigidbody>().isKinematic = false;
     transform.SetParent(GameObject.Find("handler").transform);
     _grabber = null;
 }

 private void OnTriggerEnter(Collider other)
 {
     //photonView.TransferOwnership(other.gameObject.GetPhotonView().ownerId);
 }
 private void OnTriggerExit(Collider other)
 {
     //photonView.TransferOwnership(0);
 }

I don't know what should do with that :/

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

3 Replies

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

Answer by ChristianSimon · May 08, 2018 at 09:08 AM

Hi,

how is the game object synchronized? Is it synchronized at all? If not, you can attach a PhotonView component to the prefab and network instantiate it at runtime by using PhotonNetwork.Instantiate(...); or PhotonNetwork.InstantiateSceneObject(...);. For an easy solution you can also add a PhotonTransformView component and add it to the list of Observed Components of the PhotonView component.

If a player now want to grab the object, you have to check if he is the owner first. If the client is the owner, you can continue. If he is not the owner, you have to request the ownership of the object. If the client is the owner of the object and interacts with it (basically moves it around), it should be properly synchronized on the other client as well.

You can read about Ownership Transfer here.

Comment
Add comment · Show 3 · 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
avatar image Silsor · May 08, 2018 at 09:51 AM 0
Share

Hi, I was trying so many combinations of various things, that I've lost. This object isn't instantiate. It's on the scene in specified place. Now it almost works. Objects is owned by Scene if I understand it correctly. When player Enters collider, takes the ownership. When player Exit collider ownership is setting to 0 (it means owner is scene, right?). When object is grabbed its position and rotation are equal grabber. Now it is ok. I don't know why when i set grabber as parent the object jump out from hand. It's now like this:

public void grabbedBy (Transform grabber) { grabbed = true; _grabber = grabber.gameObject; GetComponent().useGravity = false; GetComponent().is$$anonymous$$inematic = true; }

public void realesedBy(Transform grabber, Vector3 linearVelocity, Vector3 angularVelocity) { Rigidbody rigidbody = GetComponent();

     grabbed = false;
     GetComponent<Rigidbody>().is$$anonymous$$inematic = false;
     _grabber = null;
 }

 private void OnTriggerEnter(Collider other)
 {
     photonView.TransferOwnership(other.gameObject.GetPhotonView().ownerId);
 }
 private void OnTriggerExit(Collider other)
 {
     photonView.TransferOwnership(0);
 }
 private void OnTriggerStay(Collider other)
 {
     if (grabbed && _grabber != null)
     {
         transform.position = _grabber.transform.position;
         transform.rotation = _grabber.transform.rotation;
     }
 }

 void OnPhotonSerializeView(PhotonStream stream, Photon$$anonymous$$essageInfo info)
 {
     if (stream.isWriting)
     {
         stream.SendNext(transform.position);
         stream.SendNext(transform.rotation);
     }
     else
     {
         transform.position = (Vector3)stream.ReceiveNext();
         transform.rotation = (Quaternion)stream.ReceiveNext();
     }
 }

Object has PhotonView and PhotonTransformView with Interpolation set up on Estimated speed. Now the problem is that Object is shuttering, while hands of second player move smooth.

avatar image ChristianSimon Silsor · May 08, 2018 at 11:04 AM 0
Share

I guess the grabbed object has a Rigidbody component, am I right? In this case you would have to make it kinematic and disable its useGravity property as well, otherwise the client will always run his physics simulation which leads to the described behaviour. You can try adding the OnOwnershipTransfered callback (see here) and update those two properties accordingly. Firstly check, if this callback is meant to be called on this object. Then, depending on the 'newOwner', enable or disable the properties. If the 'newOwner' is the local client or any other client, the object should be kinematic, if the 'newOwner' is the scene, you should apply gravity, so that the object can fall to the ground.

avatar image Silsor ChristianSimon · May 11, 2018 at 11:30 AM 0
Share

For the end of this topic, I can add that if both Player has my script Grabber which execute grabbedBy and releasedBy i need to set up gravity of object via RPC to synchronize it. Thanks for help.

avatar image
1

Answer by art1997 · May 15, 2020 at 09:27 AM

Hello. I have similar problem. I have cube in scene, with Photon View on it, and with Transform view.

For all user, when they grab that cube, they can move it smoothly. but the movement for other not smooth. The grabbed cube is lagging, jumping.
Do you have idea, how to solve it? Can provide video of it if needed.

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
avatar image
0

Answer by Unknownperson123 · Dec 05, 2021 at 08:48 AM

listen Everyone,

i am making a fps game using photon.

i am running the dev build (two windows for two players). whenever a player jumps and i switch the window, the player who jumps seems to fall a bit and then teleport up and the cycle continues pls help

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.

Follow this Question

Answers Answers and Comments

234 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

How to fix "Creating a peer when 2 players meet" ? (in Photon) 0 Answers

Unity Photon Player Instantiation 1 Answer

SteamVR Interactable Object Problem on Photon 2 Answers

How do you Sync Avatars that aren't being controlled over the Photon Unity Network so that everyone over the network sees the same thing? 1 Answer

Syncing live animations using PUN 2 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