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

[code]
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 )
[/code] [import]uid: 46529 topic_id: 13831 reply_id: 313831[/import]

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 :wink:
http://blog.anscamobile.com/2011/08/solutions-to-common-physics-challenges/
[import]uid: 52491 topic_id: 13831 reply_id: 50890[/import]

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. [import]uid: 46529 topic_id: 13831 reply_id: 50893[/import]

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 :slight_smile: [import]uid: 52491 topic_id: 13831 reply_id: 51088[/import]

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. [import]uid: 46529 topic_id: 13831 reply_id: 51112[/import]

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

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  

shis should prevent the coin from moving outside the screen when draged…and you could do something diferent from manualy setting the new coordonates of the coin…you cound make a transition…this could make the circles to actualy colide…don’t know what could happen on high speed…but it could work fine [import]uid: 57170 topic_id: 13831 reply_id: 51116[/import]

I am having a similar problem. The objects in my case are of necessity long and thin (movable ramps). I have considered decreasing the density of EVERYTHING in the world to decrease the amount of force needed to make the object respond quickly to the physics touch joint (are you even using a touch joint?), but I feel like there should be a more straightforward, common-sense way to fix this.

In my case the objects tunnel up to a certain point and then hang back a bit.

I should also mention that the object being touch-jointed is also welded to another object of equal density but different bounce and friction. This other object is identical in shape and the two switch between one being a sensor and the other being solid, in order to make it slippery when the player moves it, but stay in place when it settles one end on the ground as a ramp.

I should probably start my own thread for this but I wanted to ask you if you have tried using the touch joint to drag physics objects? [import]uid: 63787 topic_id: 13831 reply_id: 131184[/import]

I am having a similar problem. The objects in my case are of necessity long and thin (movable ramps). I have considered decreasing the density of EVERYTHING in the world to decrease the amount of force needed to make the object respond quickly to the physics touch joint (are you even using a touch joint?), but I feel like there should be a more straightforward, common-sense way to fix this.

In my case the objects tunnel up to a certain point and then hang back a bit.

I should also mention that the object being touch-jointed is also welded to another object of equal density but different bounce and friction. This other object is identical in shape and the two switch between one being a sensor and the other being solid, in order to make it slippery when the player moves it, but stay in place when it settles one end on the ground as a ramp.

I should probably start my own thread for this but I wanted to ask you if you have tried using the touch joint to drag physics objects? [import]uid: 63787 topic_id: 13831 reply_id: 131184[/import]