My Physic Script Behave weird

Greeting gurus,

my demo is quite simple, a moving platform & a dropping box
But seems like what corona physic engine provided doesn’t make any sense in my situation

here my code, you can try run it

main.lua

[code]

local physics = require( “physics” )
physics.start()
local gGameMovement = {}

function autoMovePlatform(x1, y1, x2, y2, moveSpeed, objectRef)

local direction = 1

function reverseDirectionCallBack()

if direction == 1 then
direction = 2
xto, yto = x2, y2
else
direction = 1
xto, yto = x1, y1
end

trans = transition.to(objectRef, {time=moveSpeed, x=xto, y=yto, onComplete=reverseDirectionCallBack})

–gGroup.movement = trans
table.insert(gGameMovement, trans)

end
reverseDirectionCallBack()
end
– platform
local square = display.newRect( 0, 0, 50, 10 )
square:setFillColor( 255,255,255 )
square.x, square.y = 174, 119
autoMovePlatform(74, 119, 254, 281, 20000, square)

physics.addBody(square, ‘static’, {density=3.0, friction=0.5, bounce=0.1 } )
– dropping ball

local ball = display.newRect( 0, 0, 30, 30 )
ball:setFillColor( 255,255,0 )
ball.x, ball.y = 174, 9
physics.addBody(ball, ‘dynamic’, {density=3.0, friction=0.5, bounce=0.1 } )
[/code] [import]uid: 10373 topic_id: 4698 reply_id: 304698[/import]

Question

  • how to make the dropping box follow x,y position when it touched the platform?
  • why when it pass through the platform, the speed of dropping is insane

thank for the clarification [import]uid: 10373 topic_id: 4698 reply_id: 14878[/import]

Hi all,

I’m not sure if you or anyone figured this problem out yet but I am having a similar problem. I did some searching and found this thread with two solutions: http://developer.anscamobile.com/forum/2011/02/08/moving-objects-together

I tried solution 1 by creating a collision event that changes the object to static/kinematic when it touches the platform but that didn’t work… not quite sure about solution 2.

I read on some other thread also that instead of translating the platform with a transition.to, try a body:applyForce() instead.
http://developer.anscamobile.com/reference/index/bodyapplyforce

I’ll try that next. Basically the problem is just trying to get the object that falls on the platform to move together…

If anybody has any insights on this, it’ll be much appreciated [import]uid: 74346 topic_id: 4698 reply_id: 51041[/import]