how to make a kinematic object apply force to a dynamic one?

Hi.

I am having dificulties because I am trying to…

  • move a kinematic object (a box) with the finger…

  • and push a ball (a dynamic object) with it.

I want to move the ball with some force based on the velocity of the finger on the collision with the box…

Is there any way to accomplish this situation?  :wacko:

What does your current code look like? Remember that transition.to/translating object’s x/y locations doesn’t impact physics. Only using the Methods under the Body physics API will impact other physics objects (unless you roll your own way, of course)

If you can post the code you’re working on now, it would help steer you in the right direction.

I’m using a simple touch function to drag the kinematic object around through X and Y.
 
Something like this:

-- A basic function for dragging physics objects local function startDrag( event ) local t = event.target local phase = event.phase if "began" == phase then display.getCurrentStage():setFocus( t ) t.isFocus = true -- Store initial position t.x0 = event.x - t.x t.y0 = event.y - t.y -- Make body type temporarily "kinematic" (to avoid gravitional forces) event.target.bodyType = "kinematic" -- Stop current motion, if any event.target:setLinearVelocity( 0, 0 ) event.target.angularVelocity = 0 elseif t.isFocus then if "moved" == phase then t.x = event.x - t.x0 t.y = event.y - t.y0 elseif "ended" == phase or "cancelled" == phase then display.getCurrentStage():setFocus( nil ) t.isFocus = false -- 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

How can I make a draggable object make impact on another object while is still moving?  :wacko:

I was thinking that if I could know the speed that I am dragging something, I could “simulate” an impact when a collision occurs. Am I right? Can I know the “speed” of a draggable object?

obj:getLinearVelocity()

Ok solved with the RegionQuery sample of the Corona SDK.

Yay Corona team!  :wub:

P.S: Thx for the help guys.

What does your current code look like? Remember that transition.to/translating object’s x/y locations doesn’t impact physics. Only using the Methods under the Body physics API will impact other physics objects (unless you roll your own way, of course)

If you can post the code you’re working on now, it would help steer you in the right direction.

I’m using a simple touch function to drag the kinematic object around through X and Y.
 
Something like this:

-- A basic function for dragging physics objects local function startDrag( event ) local t = event.target local phase = event.phase if "began" == phase then display.getCurrentStage():setFocus( t ) t.isFocus = true -- Store initial position t.x0 = event.x - t.x t.y0 = event.y - t.y -- Make body type temporarily "kinematic" (to avoid gravitional forces) event.target.bodyType = "kinematic" -- Stop current motion, if any event.target:setLinearVelocity( 0, 0 ) event.target.angularVelocity = 0 elseif t.isFocus then if "moved" == phase then t.x = event.x - t.x0 t.y = event.y - t.y0 elseif "ended" == phase or "cancelled" == phase then display.getCurrentStage():setFocus( nil ) t.isFocus = false -- 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

How can I make a draggable object make impact on another object while is still moving?  :wacko:

I was thinking that if I could know the speed that I am dragging something, I could “simulate” an impact when a collision occurs. Am I right? Can I know the “speed” of a draggable object?

obj:getLinearVelocity()

Ok solved with the RegionQuery sample of the Corona SDK.

Yay Corona team!  :wub:

P.S: Thx for the help guys.

@florca Could you provide detail on your solution and mark the post as Solved, please?

+1 … @florca would love to hear more about your solution. Thanks much for sharing! 

This might be a helpful reference for anyone wanting to understand kinematic bodies:

http://www.emanueleferonato.com/2012/05/11/understanding-box2d-kinematic-bodies/

@florca Could you provide detail on your solution and mark the post as Solved, please?

+1 … @florca would love to hear more about your solution. Thanks much for sharing! 

This might be a helpful reference for anyone wanting to understand kinematic bodies:

http://www.emanueleferonato.com/2012/05/11/understanding-box2d-kinematic-bodies/