Fast drag, pass through walls - isBullet is not working

I am experimenting some stuff. I have a circle body, and walls around the screen. Circle is dynamic and walls are static bodies. I drag the circle with mouse and when i release it keeps moving - on purpose. Then it bounces the wall. Everything is ok up to here.

But if I drag the circle up to the walls with fast speed I can get it pass the walls. On low speeds collision occurs and it does not pass the wall but if I drag it fast enough, it just pass through...

I tried isBullet = true, but it doesn't help.

Any help appreciated...

Rick

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
49
50
51
52
53
54
55
local physics = require("physics")
local rand = math.random
 
physics.start()
 
physics.setGravity(0,0)
 
system.activate("multitouch")
 
display.setStatusBar(display.HiddenStatusBar)
local content = display.newGroup ( )
 
local ceiling = display.newRect( content,  0, 0, 320, 1 )
physics.addBody ( ceiling, "static", {density=1, friction=0.2, bounce=0.2} )
--
local floor = display.newRect( content,  0, 479, 320, 1 )
physics.addBody ( floor, "static", {density=1, friction=0.2, bounce=0.2} )
 
local leftWall =  display.newRect( content,  0, 1, 1, 478 )
physics.addBody ( leftWall, "static", {density=1, friction=0.2, bounce=0.2} )
 
local rightWall =  display.newRect( content,  319, 1, 100, 478 )
physics.addBody ( rightWall, "static", {density=1, friction=0.2, bounce=0.2} )
 
local coin = display.newCircle( 160, 60, 20 )
coin:setFillColor(255, 0, 0)
physics.addBody ( coin, "dynamic", {density=0.6, friction=0.2, bounce=0.2 ,radius=20} )
coin.isBullet = true
 
local onTouch = function (event)
        local target = event.target
        
        if(event.phase == "began") then
                target:setLinearVelocity(0,0)
                target.x0 = event.x
                target.y0 = event.y
                display.getCurrentStage ( ):setFocus(target)
        elseif (event.phase == "moved") then
                target.dx = event.x - target.x0
                target.dy = event.y - target.y0
                target.x = target.x + target.dx
                target.y = target.y + target.dy
                target.x0 = event.x
                target.y0 = event.y
        else
                target.linearDamping =  1
                --target:applyLinearImpulse(rand(-10,10),rand(-10,10),target.x, target.y)
                target:setLinearVelocity( target.dx * 30, target.dy * 30)
                print(target.dx)
                print(target.x0)
                display.getCurrentStage ( ):setFocus(nil)
        end
end
 
coin:addEventListener ( "touch", onTouch )

Hey culutas,

Take a look at this great post by Jon Beebe - it has helped a bunch of people solve their physics related issues already ;)
http://blog.anscamobile.com/2011/08/solutions-to-common-physics-challenges/

Thanks peach, i checked the article and applied everything in the "Objects are going through walls" topic, but still i can drag objects through the walls. It seems, if I am not doing something wrong this is just a shortcoming of SDK or Box2D.

As an alternative, have you considering manually forcing the object to stay inside the screen? Your borders are surrounding the screen so how about an event for if obj.x > 320 then obj.x = 320 etc. for each of the four edges?

Peach :)

Yes I tought about it but the boundaries are not the only problem. For example right now I added two more circles. So there are 3 draggable and throwable circles in the screen, they bounce each other and the walls, but if i move the one circle fast enough, I can pass through other circles too.

The only solution so far is not to drag directly with the finger. I checked the air hockey sample and I see that paddles are dragged indirectly, I mean, there are some limits and delays on drag, so it is not as fast as the finger.

This is not a real world problem right now, as I said I am experimenting an idea, but so far it seems, it is not possible to drag an object and follow finger at natural/exact speed.

to make the coin not pass the walls you could do something like this:

1
2
3
4
5
6
7
8
9
10
elseif (event.phase == "moved") then
    target.dx = event.x - target.x0
    target.dy = event.y - target.y0
    if (((target.x + target.dx > screenwidth-20)and (target.x + target.dx < 20)) or ((target.y + target.dy > screenheight-20)and (target.y + target.dy < 20))) then
        target.x = target.x + target.dx
        target.y = target.y + target.dy
        target.x0 = event.x
        target.y0 = event.y
    end
else
views:1523 update:2011/9/27 8:54:05
corona forums © 2003-2011