Collision force

Can I follow, or calculate the collision force of two object?

function onPostCollision( event ) print("Force:" .. event.force) end

Why is it drop back -0 and 0 in console?

Hi @naburus,

Can I see more of your code, i.e. where you set up the collision listener(s)?

Thanks,

Brent Sorrentino

Sure, here my full source code: http://pastebin.com/a7QfAXiS (Test2.lua: http://pastebin.com/jc8R5MHQ)

Hi @naburus,

What sort of value(s) are you getting reported back? Can you show me some samples, copied from the Terminal/console?

Brent

Hi

I attached my screenshot.

force.jpg

Hi @naburus,

I’m not sure how you’ve written the rest of your code, but I worked up the quick following example and I’m getting the correct force values printed out:

[lua]

local function onPostCollision( self, event )

    print(“Force:” … event.force)

end

local b1 = display.newRect( 10,10,20,20 )

physics.addBody( b1 )

local b2 = display.newRect( 10,100,20,20 )

physics.addBody( b2, “static” )

b1.postCollision = onPostCollision

b1:addEventListener( “postCollision”, b1 )

[/lua]

Can you test and confirm?

Thanks,

Brent

Works, ty.

Hi @naburus,

Can I see more of your code, i.e. where you set up the collision listener(s)?

Thanks,

Brent Sorrentino

Sure, here my full source code: http://pastebin.com/a7QfAXiS (Test2.lua: http://pastebin.com/jc8R5MHQ)

Hi @naburus,

What sort of value(s) are you getting reported back? Can you show me some samples, copied from the Terminal/console?

Brent

Hi

I attached my screenshot.

force.jpg

Hi @naburus,

I’m not sure how you’ve written the rest of your code, but I worked up the quick following example and I’m getting the correct force values printed out:

[lua]

local function onPostCollision( self, event )

    print(“Force:” … event.force)

end

local b1 = display.newRect( 10,10,20,20 )

physics.addBody( b1 )

local b2 = display.newRect( 10,100,20,20 )

physics.addBody( b2, “static” )

b1.postCollision = onPostCollision

b1:addEventListener( “postCollision”, b1 )

[/lua]

Can you test and confirm?

Thanks,

Brent

Works, ty.