Physic objects falls down when are only touched (not moved), using the startDrag function from the "Drag Platforms" source code

Hello to everyone!

I’m coding a physics game, and i have found a frustrating behavior when use the startDrag function from the “Drag Platforms” sample app source code.

I have recorded a video to show exactly what happens when you touch a body without moving it (sorry for my poor english):

http://www.youtube.com/watch?v=ADp-HTWlGKI

When i touch (without move) a draggable object, it falls down on the scenario, but comes back to the initial position. But the more times you touch (without move) the same object, the more far falls down, until it falls out of the platform.

The thing is, this only happen between dynamic objects and static objects (for example, between a box tha i’m touching, and the ground or a platform). If i have a dynamic object above another dynamic one, it doesn’t fall. And it’s frustrating because after a few touches, the object just disappear from the scenario.

I was thinking that the problem is that the body it’s already in collision when the type is set back to dynamic, so i have made a small change in the code to avoid this, setting the bodytype as “dynamic” OUT of the collision function, with no success.

When the collision ends, or is cancelled, i set the body type to “static”, and after 500 miliseconds, i turn back the body to dynamic. And nothing changes, the behavior stills happenig and the object stills falling down. It’s like if the body doesn’t collides whith the ground.

This is the code of the complete “startDrag” function i’m using, plus the additional function i have created to delay the transform of the body type from “kinematic” to “dynamic” (introducing the intermediate step “static”):

-- Function that turns the body-type of all the draggable objects to "dynamic"  
local function convierteDinamico ()  
 caja.bodyType = "dynamic"  
 tablon.bodyType = "dynamic"  
end  
   
   
--\> STARTDRAG  
--\>   
local function startDrag( event )  
 local t = event.target  
   
 local phase = event.phase  
 if "began" == phase then  
 audio.play(sonido\_pulsar)  
 display.getCurrentStage():setFocus( t )  
 t.isFocus = true  
   
 -- Store initial position  
 t.x0 = event.x - t.x  
 t.y0 = event.y - t.y  
 -- Prints the "x" and "y" values of the body, just for debug  
 print( "t.x0 =", t.x0)  
 print( "t.y0 =", t.y0)  
 print( "t.x: ", t.x )  
 print( "t.y: ", t.y )  
 print( "event.x: ", event.x )  
 print( "event.y: ", event.y )  
  
 -- Make body type temporarily "kinematic" (to avoid gravitional forces)  
 event.target.bodyType = "kinematic"  
 physics.setGravity (0, 0)  
 event.target:scale( 1.3, 1.3 )  
 event.target.alpha = 0.8  
  
 -- Stop current motion, if any  
 event.target:setLinearVelocity( 0, 0 )  
 event.target.angularVelocity = 0  
   
 elseif t.isFocus then  
 if "moved" == phase then  
 if (event.x == t.x0) or (event.y == t.y0) then  
 t.x = event.x  
 t.y = event.y  
 print( "Primer IF t.x: ", t.x )  
 print( "Primer IF t.y: ", t.y )  
 print( "Primer IF t.x: ", event.x )  
 print( "Primer IF t.x: ", event.y )  
 else  
 t.x = event.x - t.x0  
 t.y = event.y - t.y0  
 print( "t.x0 =", t.x0)  
 print( "t.y0 =", t.y0)  
 print( "Else t.x: ", t.x )  
 print( "Else t.y: ", t.y )  
 print( "Else event.x: ", event.x )  
 print( "Else event.y: ", event.y )  
 end  
   
 elseif "ended" == phase or "cancelled" == phase then  
 display.getCurrentStage():setFocus( nil )  
 t.isFocus = false  
 audio.play(sonido\_soltar)  
 physics.setGravity (0, 19.8)  
 event.target.bodyType = "static"  
 event.target:scale( 0.77, 0.77 )  
 event.target.alpha = 1.0  
 timer.performWithDelay(500, convierteDinamico, 1 )  
 -- Switch body type back to "dynamic", unless we've marked this sprite as a platform  
 -- if ( not event.target.isPlatform ) then  
 -- event.target.bodyType = "dynamic"  
  
 -- end  
   
 end  
 end  
 -- Stop further propagation of touch event!  
 return true   
end  

I am trying absolutely all the combinations of body-types, changing physics engine options, and i’m going completely crazy. :frowning: What i’m doing wrong? [import]uid: 14235 topic_id: 7434 reply_id: 307434[/import]

i can confirm this happens with an unmodified “DragPlatform” demo, included in the corona samples

direct link: http://www.youtube.com/watch?v=ADp-HTWlGKI#t=1m00s

i believe it happens because the object is already in collision when the “dynamic” body type is re-applied, although I don’t know why
[import]uid: 6645 topic_id: 7434 reply_id: 26324[/import]

Just wanted to bump this as I am experiencing this problem as well. [import]uid: 10903 topic_id: 7434 reply_id: 30839[/import]