Physics collision

Hi,

Just wondering I have a request where two objects collide with each other… I can get the force that is applied to that object… is there a way to set the force to zero so that the only force that is applied is gravity?

ie… if I throw a rock(object 1) at a rat (object 2) running on a wire above ground. When the rock collides with the rat… i want thr rat to fall straight down… at the moment the rat has the force that is applied from the force as well

Thanks

[import]uid: 67619 topic_id: 12668 reply_id: 312668[/import]

You can’t set the force of an event to 0 but it can have no effect, either by the rat being static or doing a transition to make it drop, immediately setting it’s linear velocity to 0, etc.

There’s a few options, personally if it doesn’t interfere with other elements and works for you, I like static. (Quick and easy.)

Peach :slight_smile: [import]uid: 52491 topic_id: 12668 reply_id: 46395[/import]

Peach,

If the rat is static… then gravity would not affect it yeah? which means the rat would not drop down?

sorry I am quite new to Corona… [import]uid: 67619 topic_id: 12668 reply_id: 46400[/import]

No it would not drop down with gravity BUT you could do a transition or the like to have it drop, as in as part of your collision event you could do a transition.to to make it LOOK like the rat is falling. Does that make sense? :slight_smile: [import]uid: 52491 topic_id: 12668 reply_id: 46614[/import]

try to use something like this

[lua]local physics = require “physics”
physics.start()

local rat = display.newCircle(20,100,10)
rat.myName = “rat”
local rope = display.newRect(0,130,480,2)
rope.myName = “rope”
local floor = display.newRect(0,310,480,10)
floor.myName = “floor”
physics.addBody(rope,“static”)
physics.addBody(rat)
physics.addBody(floor,“static”)
local function1,function2

function1 = function()
t1 = transition.to(rat,{x = 480 - rat.width * 0.5,time = 1500,onComplete = function2})
end

function2 = function()
t2 = transition.to(rat,{x = rat.width * 0.5,time = 1500,onComplete = function1})
end
function1()

local function addRocks(e)
local rock = display.newCircle(0,0,5)
rock.x = e.x
rock.y = e.y
rock.myName = “rock”
physics.addBody(rock,{isSensor = true})
end
Runtime:addEventListener(“tap”,addRocks)

local function onCollision( e )
if ( e.phase == “ended” ) then

if e.object1.myName == “rat” and e.object2.myName == “rock” then
print(“called”)
transition.cancel(t1)
transition.cancel(t2)
rat.isSensor = true
timer.performWithDelay(200,function() rat.isSensor = false end)

end

end
end

Runtime:addEventListener( “collision”, onCollision )[/lua] [import]uid: 12482 topic_id: 12668 reply_id: 46636[/import]

hgvyas123,

Thank you so much, that’s exactly what I needed the isSensor property… you are a legend

Thanks

[import]uid: 67619 topic_id: 12668 reply_id: 47133[/import]

legend no no i am not that i am just hgvyas [import]uid: 12482 topic_id: 12668 reply_id: 47135[/import]