Trying to make an object follow another, TsTransform lags behind

Greetings everyone,

I've tried searching for similar questions but so far I've found none.

I'm trying to make the TsTransform follow another object around, I've tried parenting but it doesn't seem to work so rather than that I've written the following:

/*** Code ***\

public override void OnSyncedInput() {
TrueSyncInput.SetTSVector(10, _parentTransfom.position);
TrueSyncInput.SetFP(13, _parentTransfom.rotation.x);
TrueSyncInput.SetFP(14, _parentTransfom.rotation.y);
TrueSyncInput.SetFP(15, _parentTransfom.rotation.z);
TrueSyncInput.SetFP(16, _parentTransfom.rotation.w);
}

public override void OnSyncedUpdate() {

myTsTransform.position = TrueSyncInput.GetTSVector(10);

FP lRotationX = TrueSyncInput.GetFP(13);
FP lRotationY = TrueSyncInput.GetFP(14);
FP lRotationZ = TrueSyncInput.GetFP(15);
FP lRotationW = TrueSyncInput.GetFP(16);

myTsTransform.rotation = new TSQuaternion(lRotationX, lRotationY, lRotationZ, lRotationW);
}

\***Code***/

However the object always seems to "drag" or "lag" behind the original one rather than accompanying it 1 to 1.

Has anyone had similar problems? Any solutions?

Thank you for your time in advance!

Best regards,

Sckir

Answers

  • Hey @Sckir, if we find some interesting solution by email feel free to post here, so other devs will get that :).

  • public void AnchorSensorsToBody(TrueSync.Physics2D.Body parent)
    {
    var bodies = GetBodyList();
    foreach ( var body in bodies )
    {
    for ( int i = 0; i < body.bodyConstraints.Count; i ++ )
    {
    var con = body.bodyConstraints[i];
    if ( con is TrueSync.Physics2D.ConstraintHierarchy2D )
    {
    TSVector2 parentCenter = TSVector2.zero;
    if ( parent != null )
    parentCenter = parent.Position;

    TrueSync.Physics2D.ConstraintHierarchy2D ch = con as TrueSync.Physics2D.ConstraintHierarchy2D;
    var offset = ch.childOffset;
    ch.parent = parent;
    ch.childOffset = body.Position - parentCenter;
    }
    }
    }
    }
    This is how I parented bodies together using their in-place constraint system. Caution, it will cause huge memory chunking if it causes two bodies to intersect.
Sign In or Register to comment.