Kinematic touch joints crashes sim

Calling newJoint on a DisplayObject with a “kinematic” physics body causes the following:

Assertion failed: (d + step.dt * k > 1.19209290e-7F), function InitVelocityConstraints

Then crashes the sim. I thought a workaround may be to set the body to “dynamic” in the touch->began phase. This works, but if you set it back to “kinematic” and touch->ended the same assertion and crash follows.

This is unexpected as the docs say draggable objects should be kinematic, even temporarily while dragging. So doing this according to the docs also causes the crash.

If it’s just draggable button, setting it to static, switching to dynamic in “began” then back to static in “ended” works, but of course it won’t interact with other objects unless you’re dragging it.

Handler dragBody is same as in Corona sample code and docs;

local ball = display.newCircle(100, 100, 30)  
ball:setFillColor(255, 0, 0)  
physics.addBody(ball)  
ball.bodyType="kinematic" -- static and dynamic OK  
ball:addEventListener( "touch", dragBody )  

Crash happens here in the phase==“began” block of dragBody:

body.tempJoint = physics.newJoint( "touch", body, event.x, event.y )  

if you firstly set it to dynamic you can drag it OK. But if you set it back to kinematic:

 elseif "ended" == phase or "cancelled" == phase then  
 body.bodyType = "kinematic" -- OK so far  

The handler exits OK but the sim crashes before anything else is displayed.

If I’m doing this the wrong way hopefully someone can correct me. [import]uid: 3953 topic_id: 1899 reply_id: 301899[/import]

Looking into this, but I would suggest NOT setting the body type to “kinematic” in this case, since there’s no real need for it.

There are basically two methods for dragging objects, and they’re quite different:

(1) The method shown in “DragPlatforms”, where you temporarily remove the dragged object from active simulation by making it “kinematic”, and then force the position updates back into the physics world. The advantage is that the dragged object can be moved as fast as your finger, since it’s not subject to any physical forces. The disadvantage is that it can be pushed right through solid objects – since it’s not subject to any physical forces.

(2) The method shown in “DebugDraw”, using a “touch” joint. The advantage is that the dragged object will behave properly within the simulation, and continue to interact with other objects, including stopping at solid barriers. The disadvantage is that it may lag behind your finger, since it has to obey laws of physics, which say that you can have a very large force, but not an INFINITELY large force.

In general, method (2) is probably more useful in a physics-based game, but in that case you should not set the body to “kinematic”. It sounds like we need to update the docs to make this clearer.

Also, it definitely should not crash, so that’s logged as internal bug #910. [import]uid: 3007 topic_id: 1899 reply_id: 5631[/import]

I’m using the method 2 but having problems integrating with camera scrolling: any idea?

https://developer.anscamobile.com/forum/2010/11/20/sort-mouse-joints

any idea? [import]uid: 10482 topic_id: 1899 reply_id: 11592[/import]

I’m having problems with this issue too.

I’m developing a game in which items of refuse fall from the top of the screen and the player has to sort them into the correct recycling boxes along the bottom of the screen.

In my situation I want the drag function to utilise a “touch” joint as in the gameUI function because I think it’s tidier and I want to simulate inertia and momentum on release.

However I also want the player to be able to drag the objects through the floor of the physics world (my boxes are below floor level), which seems to work nicely if I switch the body type to kinematic as in the DragPlatforms example.

I pondered using categoryBits and maskBits but I want my falling items to stop at floor level unless dragged downwards and you can’t seem to change these after the physics body has been created.

Is there a fix to the kinematic-touch-joint crashing problem yet or does anyone know of another method for dragging dynamic bodies through each other while maintaining physics interactions?

Please help. [import]uid: 11712 topic_id: 1899 reply_id: 27917[/import]