Recording and Playback of Object Positions Returns Odd Results

I’ll try to explain this as best I can.

Long story short,

 - I have  two bodies joined with a pivot joint

  • Moving one body works great. Nice desired, smooth motion with the intended range of motion

  • At every motion, the x,y coordinates are recorded into a table for “playback”

  • During “recording”, no joints are broken even if the object is dragged away from the joint; the bodies stay connected

However…

  • During playback, the object is moved similarly to the recorded movements

  • Except that the object is visually  disconnected from the joint if the recorded actions dictated; as a result the two objects become separated (but this does NOT happen during recording)

What can be done to ensure joint integrity is maintained when previous positions are read from a table and used to transition.to()?

Please advise. Thanks!

Hi @rbsmith5,

How often during “motion” are you recording the x/y change into the table? On every single tiny incremental “moved” phase response? That would potentially be thousands of recorded position changes, correct? In any case, once you have it recorded, how are you doing the transition for playback? Do you run a new transition from each x/y point to the next x/y point in the recorded path?

Brent

Hi Brent… You are correct, I store every x/y value for the drag event for this particular object. Yes that could be a lot of data points. For now it’s only a about a hundred or so. I feed these values into a table and read them out into trasition.to() statements for “playback”. What’s odd is that during “dragging” the joints behave perfectly on screen but debug statements show x/y values that separate from the joint. During playback is when you see the objects break away from their joint.

Here is a clip of the issue:

https://youtu.be/ZuRrWIPg0xM

Thanks!

Hi @rbsmith5,

If you’re capturing every x/y value during the drag, you might see better results during “playback” by just moving the object by Runtime position changes instead of transitions. While that might (in some cases) produce a jerky playback, because you’re capturing every point along the drag, it should actually be pretty smooth. If the rate of playback is too fast, you could incrementally move them via a very short repeating timer (10-50 milliseconds or something).

Can I see how you’ve set up your physics bodies and joints, by the way? Just one example I mean, like the arm/shoulder you showed in the video.

Thanks,

Brent

Hi Brent,

Here are the definitions you requested:

– torso positioning

       --layer.torso = display.newImageRect( composer.imgDir… “p1_torso.png”, 584, 1006 );

       layer.torso = display.newImageRect( composer.imgDir… “chewbacca-torso.png”, 584, 1006 );

       layer.torso.x = 754; layer.torso.y = 554; layer.torso.alpha = 1; layer.torso.oldAlpha = 1

       layer.torso.oriX = layer.torso.x; layer.torso.oriY = layer.torso.y

       layer.torso.oriXs = layer.torso.xScale; layer.torso.oriYs = layer.torso.yScale

       layer.torso.name = “torso”

       sceneGroup:insert( layer.torso); sceneGroup.torso = layer.torso

– right arm

layer.right_arm = display.newImageRect( composer.imgDir… “chewbacca-right-arm.png”, 368, 636 );

       layer.right_arm.x = 1103; layer.right_arm.y = 709; layer.right_arm.alpha = 1; layer.right_arm.oldAlpha = 1

       --layer.right_arm.x = 1024; layer.right_arm.y = 1345; layer.right_arm.alpha = 1; layer.right_arm.oldAlpha = 1

       layer.right_arm.oriX = layer.right_arm.x; layer.right_arm.oriY = layer.right_arm.y

       layer.right_arm.oriXs = layer.right_arm.xScale; layer.right_arm.oriYs = layer.right_arm.yScale

       layer.right_arm.name = “right_arm”

       sceneGroup:insert( layer.right_arm); sceneGroup.right_arm = layer.right_arm

physics.addBody(layer.right_arm, “dynamic”, {density=1, friction=.4, bounce=0, radius=204})

       layer.right_arm.myName = “right_arm”

physics.addBody(layer.torso, “static”, {density=1, friction=.4, bounce=0, radius=292})

       layer.torso.myName = “torso”

local right_armtorso = physics.newJoint(“pivot”, layer.torso,layer.right_arm,  989, 475)

Hi @rbsmith5,

How often during “motion” are you recording the x/y change into the table? On every single tiny incremental “moved” phase response? That would potentially be thousands of recorded position changes, correct? In any case, once you have it recorded, how are you doing the transition for playback? Do you run a new transition from each x/y point to the next x/y point in the recorded path?

Brent

Hi Brent… You are correct, I store every x/y value for the drag event for this particular object. Yes that could be a lot of data points. For now it’s only a about a hundred or so. I feed these values into a table and read them out into trasition.to() statements for “playback”. What’s odd is that during “dragging” the joints behave perfectly on screen but debug statements show x/y values that separate from the joint. During playback is when you see the objects break away from their joint.

Here is a clip of the issue:

https://youtu.be/ZuRrWIPg0xM

Thanks!

Hi @rbsmith5,

If you’re capturing every x/y value during the drag, you might see better results during “playback” by just moving the object by Runtime position changes instead of transitions. While that might (in some cases) produce a jerky playback, because you’re capturing every point along the drag, it should actually be pretty smooth. If the rate of playback is too fast, you could incrementally move them via a very short repeating timer (10-50 milliseconds or something).

Can I see how you’ve set up your physics bodies and joints, by the way? Just one example I mean, like the arm/shoulder you showed in the video.

Thanks,

Brent

Hi Brent,

Here are the definitions you requested:

– torso positioning

       --layer.torso = display.newImageRect( composer.imgDir… “p1_torso.png”, 584, 1006 );

       layer.torso = display.newImageRect( composer.imgDir… “chewbacca-torso.png”, 584, 1006 );

       layer.torso.x = 754; layer.torso.y = 554; layer.torso.alpha = 1; layer.torso.oldAlpha = 1

       layer.torso.oriX = layer.torso.x; layer.torso.oriY = layer.torso.y

       layer.torso.oriXs = layer.torso.xScale; layer.torso.oriYs = layer.torso.yScale

       layer.torso.name = “torso”

       sceneGroup:insert( layer.torso); sceneGroup.torso = layer.torso

– right arm

layer.right_arm = display.newImageRect( composer.imgDir… “chewbacca-right-arm.png”, 368, 636 );

       layer.right_arm.x = 1103; layer.right_arm.y = 709; layer.right_arm.alpha = 1; layer.right_arm.oldAlpha = 1

       --layer.right_arm.x = 1024; layer.right_arm.y = 1345; layer.right_arm.alpha = 1; layer.right_arm.oldAlpha = 1

       layer.right_arm.oriX = layer.right_arm.x; layer.right_arm.oriY = layer.right_arm.y

       layer.right_arm.oriXs = layer.right_arm.xScale; layer.right_arm.oriYs = layer.right_arm.yScale

       layer.right_arm.name = “right_arm”

       sceneGroup:insert( layer.right_arm); sceneGroup.right_arm = layer.right_arm

physics.addBody(layer.right_arm, “dynamic”, {density=1, friction=.4, bounce=0, radius=204})

       layer.right_arm.myName = “right_arm”

physics.addBody(layer.torso, “static”, {density=1, friction=.4, bounce=0, radius=292})

       layer.torso.myName = “torso”

local right_armtorso = physics.newJoint(“pivot”, layer.torso,layer.right_arm,  989, 475)