Using HingeJoints in TrueSync?

Hi, for my Unity multiplayer game I need some HingeJoints to be synced. Since there is no "TSHingeJoint" in TrueSync (at least I don't know about it): What is the best way to implement a Hinge Joint into TrueSync?

Comments

  • Hi @airborne,

    For now you could do it manually adjusting body positions, but it is a feature that we should add in the future.
  • airborneairborne
    edited January 2017
    Hmm, that's a little bit disappointing. Implementing a Hinge Joint algorithm is not straightforward, especially in a code environment I'm not familiar with. May I ask: Is it a feature you are already working on and can be expected to be released soon or is it not in the foreseeable future?
  • Yes @airborne, I agree with you. About what you ask you have an implementation for 2D physics but it is not tested yet, we should do it soon.
  • airborneairborne
    edited January 2017
    Hmm, too bad I'm working on a 3D game :( . Maybe I'll give it a try to write my own HingeJoint implementation. I actually worked for several years as a programmer of scientifical software, so I don't think it's impossible for me. Do you think it's possible for you to help me out with some advice? Maybe some pseudo code, paper about the theoratical background etc. I'd appreciate it
  • Hello @airborne, I have two good news for you, one is that this feature can be included in next releases first for 3D physics and second is that you can check HERE an implementation of HingeJoint that may help you if you want to try by yourself.
  • airborneairborne
    edited January 2017
    Hi @JeffersonHenrique, that's great to hear. Can you tell me when approximately the release date is gonne be? I'm gonna have a look into the the jitterphysics HingeJoint implementation. Is TrueSyncs Physics Engine based on jitterphysics?
  • Hi @airborne, yes we have a 3D physics based on Jitter. The release (1.0.9) possibly including a HingeJoint can be released next week (first week of February).
  • Hi @JeffersonHenrique . Thx, great news. Just one more question ;) Will the HingeJoint have the option to implement min and max limits? Because in jitter physics there are two kind of Hinge Joints: One without limits and one with limits.
  • We will try to include both types @airborne :)
  • @JeffersonHenrique . I just installed version 1.0.9. I've noticed that there is no new component called "TSHingeJoint" or similar. In the change log though I found the note "Added "HingeJoint.Create" to allow creation of simple hinge joints between two 3D bodies"
    Since I couldn't find much documentation on ow to use it correctly I just gave it a shot attaching the following script to a GameObject containing a TSRigidbody:
    using UnityEngine; using TrueSync; public class AddJoint : TrueSyncBehaviour { TSRigidBody thisBody; [SerializeField] TSRigidBody otherRigidbody; void Start() { thisBody = GetComponent(); TrueSync.HingeJoint.Create(PhysicsWorldManager.instance.GetWorld(), thisBody.tsCollider.Body, otherRigidbody.tsCollider.Body, new TSVector(1, 0.5, 0), TSVector.up); } }
    Unfortunately I doesn't work as expected. Could you guid me a little bit how to use it correctly (or give me a link to some documentation). And will there be a TSHingeJoint Component in a future release which can be used similar to a Unity builtin HingeJoint?
  • @JeffersonHenrique . I just installed version 1.0.9. I've noticed that there is no new component called "TSHingeJoint" or similar. In the change log though I found the note "Added "HingeJoint.Create" to allow creation of simple hinge joints between two 3D bodies"
    Since I couldn't find much documentation on ow to use it correctly I just gave it a shot attaching the following script to a GameObject containing a TSRigidbody:
    using UnityEngine; using TrueSync; public class AddJoint : TrueSyncBehaviour { TSRigidBody thisBody; [SerializeField] TSRigidBody otherRigidbody; void Start() { thisBody = GetComponent(); TrueSync.HingeJoint.Create(PhysicsWorldManager.instance.GetWorld(), thisBody.tsCollider.Body, otherRigidbody.tsCollider.Body, new TSVector(1, 0.5, 0), TSVector.up); } }
    Unfortunately I doesn't work as expected. Could you guid me a little bit how to use it correctly (or give me a link to some documentation). And will there be a TSHingeJoint
  • @JeffersonHenrique . I just installed version 1.0.9. I've noticed that there is no new component called "TSHingeJoint" or similar. In the change log though I found the note "Added "HingeJoint.Create" to allow creation of simple hinge joints between two 3D bodies"
    Since I couldn't find much documentation on ow to use it correctly I just gave it a shot attaching the following script to a GameObject containing a TSRigidbody:
    using UnityEngine; using TrueSync; public class AddJoint : TrueSyncBehaviour { TSRigidBody thisBody; [SerializeField] TSRigidBody otherRigidbody; void Start() { thisBody = GetComponent(); TrueSync.HingeJoint.Create(PhysicsWorldManager.instance.GetWorld(), thisBody.tsCollider.Body, otherRigidbody.tsCollider.Body, new TSVector(1, 0.5, 0), TSVector.up); } }
    Unfortunately I doesn't work as expected. Could you guid me a little bit how to use it correctly (or give me a link to some documentation). And will there be a TSHingeJoint
  • @JeffersonHenrique . I just installed version 1.0.9. I've noticed that there is no new component called "TSHingeJoint" or similar. In the change log though I found the note "Added "HingeJoint.Create" to allow creation of simple hinge joints between two 3D bodies"
    Since I couldn't find much documentation on ow to use it correctly I just gave it a shot attaching the following script to a GameObject containing a TSRigidbody:
    using UnityEngine; using TrueSync; public class AddJoint : TrueSyncBehaviour { TSRigidBody thisBody; [SerializeField] TSRigidBody otherRigidbody; void Start() { thisBody = GetComponent(); TrueSync.HingeJoint.Create(PhysicsWorldManager.instance.GetWorld(), thisBody.tsCollider.Body, otherRigidbody.tsCollider.Body, new TSVector(1, 0.5, 0), TSVector.up); } }
    Unfortunately I doesn't work as expected. Could you guid me a little bit how to use it correctly (or give me a link to some documentation). And will there be a TSHingeJoint
  • Sorry for the multi-post, don't know what happened.
  • Hello @airborne, you are right, there is no related TSHingeJoint yet, I decided to not put there because the implementation of HingeJoint doesn't completely match with Unity's version. If you add this lines on the script SimpleControl you will create a HingeJoint between two of the blue boxes created on the scene after you press the space button.

    // Instantiates a new ball belonging to current player if the following criteria is true if (!lastCreateState && currentCreateState && !createdRuntime) { GameObject go1 = GameObject.Find("Box(Clone)"); go1.name = "Cube1"; GameObject go2 = GameObject.Find("Box(Clone)"); go2.name = "Cube2"; TrueSync.HingeJoint.Create(PhysicsWorldManager.instance.GetWorld(), go1.GetComponent().Body, go2.GetComponent().Body, TSVector.zero, TSVector.up); (....)
  • airborneairborne
    edited February 2017
    Thanks. I think the "position" parameter in HingeJoint.Create is in world coordinates in contrast to Unitys HingeJoint where you enter the position of the anchor in local coordinates, right? I added these three lines in order to match better with Unitys Hinge Joint input:
    Vector3 localPos = new Vector3(-0.5f, 0, 0); //(local) anchor position, later from inspector Vector3 worldPos=go2.transform.TransformPoint(localPos); TSVector TSworldPos = worldPos.ToTSVector();
    And then use TSworldPos as the parameter when creating the hinge joint.
    Using Limits is not possible right now?
  • Hello @airborne, you are totally right about world coordinates, currently the use of limits it is not implemented on the HingeJoint.
  • Is there any reason why the HingeJoint constructor has been declared private in the new TrueSync version? It's a little bit annoying that I can't create my own instance of HingeJoint (HingeJoint.Create has return type void) in order to use tha class methods (like Deactivate() when trying to implement some break force behaviour)
  • airborneairborne
    edited February 2017
    Hi, I decided to write my own HingeJoint implementation after all. I've uploaded a sample project here https://github.com/LudwigK84/TrueSyncHingeJoint . It's a very simple implementation but its fine for what I need. You can enter Limits, breakforce and spring values. The input matches with Unitys builtin Hinge Joint, though it has less features. Everyone is free to use it as a baseline for their own implementation or contribute, I can't give any guarantee that it works of course. For more infos read the readme file
  • Hello @airborne, congrats, thanks for sharing.
Sign In or Register to comment.