How to Connect to PUN 2 using Bullet Physics in Unity

hello,

i am trying to add a rigidbodyView to sync my rigidbodies but i am using bullet physics not unity physics.

the RigidBody view Requres component of type Rigidbody..

i cannot add library using BulletUnity;
so that i change to Requres component of type BRigidBody..

how can i make this work?

Comments

  • M4TT
    M4TT
    edited December 2019
    When u say you use bullet physic, are you using a script called like this ?
    As I understand you are not moving your bullet using unity physics but using regular methods, like for example transform.Translate and you want to sync these bullets for each player.

    You should use both photon view and photon transform view components into your bullet prefab and make sure your transform view is observing the photon view of the bullet.
    I guess that's it, now the bullet is synced for others players, it's the same way with a rigidbody but with another specific component as u mentioned.
    I send you back to the photon tutorials & demo here :
    https://doc.photonengine.com/en-us/pun/current/demos-and-tutorials/pun-basics-tutorial/player-networking
  • no bullet physics, is an open source physics library. it has all the same components of a physics engine, such as rigidbodies, collision detection, and addForce functions.. it is like Box2D if u have ever hear of it, but in 3D..

    the issue is that i am using Unity. i am using Pun2.. thus Photon Unity Network should be valid. but i am not using the unity physics. Ie. PhysX.

    so my question remains.. How to use Bullet Physics in Conjuntion with unity, and Photon Pun2
  • namespace Photon.Pun
    {
        using UnityEngine;
       
    
        [RequireComponent(typeof(PhotonView))]
        [RequireComponent(typeof(Rigidbody))]
        [AddComponentMenu("Photon Networking/Photon Rigidbody View")]
        public class PhotonRigidbodyView : MonoBehaviour, IPunObservable
        {
            private float m_Distance;
            private float m_Angle;
    
            private Rigidbody m_Body;
    
            private PhotonView m_PhotonView;
    
            private Vector3 m_NetworkPosition;
    
            private Quaternion m_NetworkRotation;
    

    this is a snippet that i was reffering to earilier, in which namespace Photon.Pun Requires component of type Rigidbody.
  • As I know there is 3 way on Photon to synchronize your prefab for each player :
    - Using Photon Rigidbody View
    - Using custom method with OnPhotonSerializeView
    - Using Photon Transform View

    These 3 options must be observed by the Photon View to works.

    As I said in my first post you can use Photon Transform View instead of Rigidbody View
    Did you take a look on the link I mentioned ? There is everything you currently need ;)
  • Ok, so if i understand you. you are telling me that Photon RigidBodyView is not Neccessary.. i can use transformView to just update the transform simply..

    i did this, i tried your method. But when i do rb.AddImpulse. the object is thrown forward for the local client, but is not moved on the non local client..

    why is this happening?

    i have other objects which also have transformView on them which are updating for both clients but these objects are just having their transforms changed.. no physics action..

    is this because possibly add impulse happens at to small a time frame for it to be caught by the server and applied on the other client?

    in my case, there are two physics instances, and i just addImpulse and let the physics do the calculations localy for each client..

  • Can I have a screenshot of your whole photon view component on your bullet prefab ?
    is this because possibly add impulse happens at to small a time frame for it to be caught by the server and applied on the other client?
    No, it's not possible in my opinion.
  • Elias992
    Elias992
    edited December 2019
    its not a bullet prefab..
    its a cue ball..

    there is no bullet prefab..

    bullet is a physics library

    https://google.com/search?q=bullet+physics&rlz=1C1CHBF_enLB867LB867&oq=bullet+physics+&aqs=chrome..69i57j69i59j69i60l2j69i65l3j69i60.3238j0j7&sourceid=chrome&ie=UTF-8

    Here is my PhotonView Component

    https://imgur.com/xRt4vEk






  • You never said that it was a cue ball Q_Q
    Is there the same issue if you set observe option on unreliable on change ?

    Are the cue ball instantiated when you start the game mode or are they already in the scene ?
    If they are instantiated can you past the part of this code here please ?

  • Elias992
    Elias992
    edited December 2019
    same when set to unreliable on change

    no the are instantiated on both players connected..

    this is called only after PhotonNetwork.CurrentRoom.PlayerCount == 2

    public void SetUpLagShot()
        {
            if (PhotonNetwork.IsMasterClient && playerOneCueBall == null)
            {
                playerOneCueBall = PhotonNetwork.Instantiate("CueBallPlayerOne", new Vector3(xPositionForLagShot, APEX_POINT.y, (slateOrPlayingField.transform.position.z + LAG_SHOT_SEPERATION)), INITIAL_BALL_ROTATION);
                playerOneCueBall.name = "CueBallPlayerOne";
                Destroy(playerOneCueBall.GetComponent<BallInHandCueBall>());
                playerOneCueBallPointOfRotation = PhotonNetwork.Instantiate("CueBallPointOfRotationPlayerOne", new Vector3(xPositionForLagShot, APEX_POINT.y, (slateOrPlayingField.transform.position.z + LAG_SHOT_SEPERATION)), POINT_OF_ROTATION_ROTATION);
                playerOneCueBallPointOfRotation.name = "CueBallPointOfRotationPlayerOne";
            }
            else
            {
                cueBallPlayerOneAvailable = true;
            }
    
            if (!PhotonNetwork.IsMasterClient && playerTwoCueBall == null)
            {
                playerTwoCueBall = PhotonNetwork.Instantiate("CueBallPlayerTwo", new Vector3(xPositionForLagShot, APEX_POINT.y, (slateOrPlayingField.transform.position.z - LAG_SHOT_SEPERATION)), INITIAL_BALL_ROTATION);
                playerTwoCueBall.name = "CueBallPlayerTwo";
                Destroy(playerTwoCueBall.GetComponent<BallInHandCueBall>());
                playerTwoCueBallPointOfRotation = PhotonNetwork.Instantiate("CueBallPointOfRotationPlayerTwo", new Vector3(xPositionForLagShot, APEX_POINT.y, (slateOrPlayingField.transform.position.z - LAG_SHOT_SEPERATION)), POINT_OF_ROTATION_ROTATION);
                playerTwoCueBallPointOfRotation.name = "CueBallPointOfRotationPlayerTwo";
            }
            else
            {
                cueBallPlayerTwoAvailable = true;
            }
        }
    
  • Do you already tried to drag and drop the transform of your cue ball to the observed component of the photon view ?
    ( I mean the unity transform x,y,z,w )

  • when i have 2 instances of the game connected through photon i have cuesticks which have the same configuration as the cueballs, but the cue sticks work fine. i move one, it moves on the other instance of the game...

    i just tried to drag, drop, it still had same effect
  • As I know, if you are using physic you can synchronize the transform instead of the rigidbody
    On your screen there is a rigidbody attached to the cue ball, have you ever try to drag and drop it in the rigidbody view and to observe the rigidbody with the photon view ?