Photon TrueSync possible bug with collider orientation

I've been experimenting with TrueSync, trying to adapt it for my own uses with a multiplayer networking game and I think I've stumbled across a possible bug. I recorded a video to show what's going on here: https://sendvid.com/drcdnege

In the video it shows the current selection is the Test gameobject, which shows its components in the panel. I change the transform rotation of the Y-axis and the scene view displays the box collider out of alignment. I'm not sure why it would do this. I then change the rotation back to zero and perform a test run. During the test run the balls somehow travel through the Test gameobject (in green). Could I be using the collider incorrectly or did I discover an actual bug?

If it's possible I'm using it incorrectly, how should it be used? My Test gameobject has a child with just a meshrenderer and a meshfilter in it. All of the physics components are displayed in the panel, so just a Transform, TSTransform, TSBoxCollider, and TSRigidBody. The script causing the rotation of the Test gameobject is just a modified version of SimpleControl.cs, the script that comes in the Boxes demo of the TrueSync package from the asset store. The line of code that does the rotation just applies torque to the TSRigidBody component about the Y-axis.

Comments

  • Oh, I see. The center vector value in the TSBoxCollider component provides a world-space offset. I thought it was for a local space offset. I'm not sure how I can change that, but I'll look into it.
  • Hi, we'll take a look here and see how we can expose these properties better.

    Please, feel free to post any other questions here.
  • ScriptGeek
    edited November 2016
    After looking at this a bit more, I realize what's happening with the collider is not actually what was intended. Have a look at this video: https://sendvid.com/dyh1bpur

    Observe the values shown in the TS Box Collider (Script) panel, the center is: (0, 0, 0.5) and the size is (1, 1, 2). Notice how as the gameobject rotates its collider also rotates, but the collider remains at the same position when given that the center is offset, the rotation of the gameobject should cause this offset to reposition the collider.

    I looked through the code and found the position of the gizmo being drawn is calculated here in the code snippet as follows;
    TSCollider.cs
    /** * @brief Do a base matrix transformation to draw correctly all collider gizmos. **/ public virtual void OnDrawGizmos() { if (!this.enabled) { return; } Vector3 position = _body != null ? _body.Position.ToVector() : (transform.position + ScaledCenter.ToVector()); Quaternion rotation = _body != null ? _body.Orientation.ToQuaternion() : transform.rotation; Gizmos.color = Color.yellow; Matrix4x4 cubeTransform = Matrix4x4.TRS(position, rotation, GetGizmosSize()); Matrix4x4 oldGizmosMatrix = Gizmos.matrix; Gizmos.matrix *= cubeTransform; DrawGizmos(); Gizmos.matrix = oldGizmosMatrix; }

    The positioning calculation doesn't account for a non-zero vector for the collider center value. This video shows how the position is correct when the center is a zero vector: https://sendvid.com/23x9dwug

    The solution to this issue is to change the position calculation line within the OnDrawGizmos method in the TSCollider.cs script to this:
    Vector3 position = _body != null ? _body.Position.ToVector() : (transform.position + rotation * ScaledCenter.ToVector());

    This applies the proper rotation to the scaled center vector and the position is now accurately applied. Is there a better place to put this positioning code for the collider at runtime?
  • ScriptGeek
    edited November 2016
    OK, so this fix is a solution for setting the correct position for the gizmos in the editor, but it doesn't solve the problem when physics objects will pass through each other during runtime if the gameobjects rotation and incorrect collider positions allow it. I'm looking for where the collider position is updated so I can fix this. Or rather, where the physics is calculated for the gameobject, then the collider position also needs updating.
  • I must not be explaining this correctly. I'm not getting anywhere trying to find out where to adjust the collider position with its current transform rotation and the collider center offset. TSTransform.position doesn't change, only transform.position. I don't know how to get the collider's position to change, I thought setting a non-zero vector value in the TSBoxCollider should offset the collider and rotating the gameobject would cause the position of the collider to rotate around the pivot of the gameobject. Why doesn't it work? Do I have this completely wrong? I'm lost.
  • Hello @ScriptGeek, I saw the videos you made, I will reproduce what you did with the box collider to check out what is going on under the hood, thanks for your feedback.
  • ScriptGeek
    edited December 2016
    @JeffersonHenrique That's awesome! I did manage to find a workaround for my immediate needs, but it is a bit awkward and restrictive on flexibility into the future. I created 2 gameobjects and set one as the child to the other. The parent contains the TSRigidBody and the child contains the MeshFilter and MeshRenderer, then the local position is moved to provide an offset from the center of its parent gameobject. This is not ideal and feels very hacky, but it does work for my specific case for now. Thank you for the support!
  • This is an issue with lack of support for compound colliders, which was discussed in another thread here: http://forum.photonengine.com/discussion/comment/32516#Comment_32516

    As of version 1.0.7 there was no ability to implement compound colliders.