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

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 :)

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...

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? :)

try to use something like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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 )

hgvyas123,

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

Thanks

legend no no i am not that i am just hgvyas

views:1899 update:2011/9/17 18:17:57
corona forums © 2003-2011