Rectangle issues

I put the rectangle as bullet it didn’t work and then I put both the Ball and rectangle as bullet and it doesn’t work 

And… you read the guide right?

Oh, and how are you moving the ‘bullet’?

As @davebollinger correctly points out:

If you’re moving any part of this conglomeration using manual discrete changes you’ll probably get tunneling.

I see you’ve got the exact code I gavein my example showing you how to stop the ‘wall’ from moving.

I added this bit:

 self.x = self.x0 + dx self.y = self.y0 + dy 

To allow you to try the example over and over to see that it did indeed stop moving when you lifted your finger.

It isn’t going to be correct to use that for some kind of interaction.

In short, you have to use all physics movement to make a paddle (which is what you sound like your trying to do).

yes

-- create image of a ball Ball = display.newCircle(100, 20, 10) physics.addBody(Ball, "dynamic", {bounce = 0.1, density=.1}) Ball:setFillColor( 1.5, 0.2, 0.2 ) Ball:setStrokeColor( 0, 0, 5 ) Ball.isBullet = true Ball:applyLinearImpulse( .1, .00, 0, 0)
-- create object local myRectangle = display.newRect( 100, 100, 70, 15 ) myRectangle:setFillColor( 0.5, 0.2, 0.2 ) physics.addBody(myRectangle, "static", {friction = 2, density=5}) -- touch listener function function myRectangle:touch( event ) if event.phase == "began" then display.currentStage:setFocus( self, event.id ) self.isFocus = true self.x0 = self.x self.y0 = self.y elseif( self.isFocus ) then local dx = event.x - event.xStart local dy = event.y - event.yStart self.x = self.x0 + dx self.y = self.y0 + dy if event.phase == "ended" then display.currentStage:setFocus( self, nil ) self.isFocus = false end end return true end

How do I make the objects solid ?

yeah, I’ve got nothing else.  I don’t have a clear picture of what you want the full gamut of interactions to be.

If you’re not doing discrete movements, is bullet should work. 

I’d check the size and thickness of my physics bodies.

Failing that, I’d look into the API (https://docs.coronalabs.com/daily/api/library/physics/index.html) and pay particular attention to:

physics.setPositionIterations()

physics.setVelocityIterations()

Solid?  Solid is not a concept in Box2D.

There are two major attributes to Box2D physics simulation (and for most other simulated game physics engines too):

  • Collision Detection - The engine determines there was a collision (or will be) and fires an event.
    • Corona SDK has the concept of ‘listeners’.  i.e. Code listening for events.
    • You choose what actions to take in listeners when a collision is detected.
  • Collision Response - This is the physical part we normally associate with real world physics: bouncing, pushing, etc.
    • By default, all objects that can collide with each other respond to those collisions.
    • By default, all bodies collide with all other bodies, but this can be changed via the filter when adding a body.
    • Additionally, if you set ‘isSensor’ to true, the ‘response’ part of Box2D is turned off for that object.  Only detection works.  By default, isSensor is false.

You must also understand that collision detection is discrete and not continuous. 

That is, where in the real world an object moves like this:

:lol: ---------------------------------------> :lol:

In the simulated environment, it is more like this:

:blink:              ??               ??                :blink:

t0                 t1                t2                t3  

This means, that in the real world for a time between t2 and t3, the object’s position is known.  In the simulated world it must be interpolated.

This in turn means that collisions, which are only checked at discrete times can miss a collision.  This is where the concept of tunneling comes from.

At the end of the day, you must know this to properly create a game that will detect and respond to collisions when you want it to.

PS - Going offline.  No further responses will be forthcoming till later.

How can I make it thick enough for the ball to not go through ? This is what I have now :

local myRectangle = display.newRect( 100, 100, 70, 15 ) myRectangle:setFillColor( 0.5, 0.2, 0.2 ) physics.addBody(myRectangle, "static", {hasBody = true, friction = 2, density=5})

-- create image of a ball Ball = display.newCircle(100, 20, 10) physics.addBody(Ball, "dynamic", {radius=10, bounce = 0.1, density=.1}) Ball:setFillColor( 1.5, 0.2, 0.2 ) Ball:setStrokeColor( 0, 0, 5 ) Ball.isBullet = true Ball:applyLinearImpulse( .1, .00, 0, 0)

I modified your code slightly and am not seeing a penetration/tunneling issue.

 

local physics=require("physics") physics.start() physics.setGravity( 0, 0 ) --physics.setDrawMode('hybrid') local rect = display.newRect( display.contentCenterX, display.contentCenterY, 70, 15 ) rect:setFillColor( 0.5, 0.2, 0.2 ) physics.addBody(rect, "static", { friction = 2, density=5 } ) local ball = display.newCircle( display.contentCenterX, display.contentCenterY - 150, 10) physics.addBody(ball, "dynamic", {radius=10, bounce = 0.1, density=.1}) ball:setFillColor( 1.5, 0.2, 0.2 ) ball:setStrokeColor( 0, 0, 5 ) ball.isBullet = true ball:applyLinearImpulse( 0, 100 \* ball.mass, ball.x, ball.y )

That doesn’t work . The ball bounces up from the rectangle once and the moves very slowly until it hits the rectangle and then nothing else happens .

I’m aware of that.  I wasn’t trying to solve your problem.
 
I was trying to demonstrate that there is not a problem with passing through the block.
 
I also fixed several errors in your general use of Corona.  If you apply the concepts you see in my code to yours, you’ll probably be closer to the solution you want.
 
You’ve asserted that something is happening that is not happening.  There is no way you should be getting tunneling.
 
You’re doing a few small wrong things in your code:

physics.addBody(myRectangle, "static", {hasBody = true, friction = 2, density=5})

should be

physics.addBody(myRectangle, "static", { friction = 2, density=5})

hasBody is not a physics parameter
 
I don’t know what you’re trying to do here, but I know it is wrong:

-- Why are you moving it to the right? -- Why no leading zero? .1 should be 0.1 for legibility -- last two args should be: Ball.x, Ball.y instead of 0,0 Ball:applyLinearImpulse( .1, .00, 0, 0) 

AT THE END OF THE DAY THERE IS NO ISSUE WITH CORONA, PHYSICS, OR TUNNELING.

The ball still does go through the rectangle and the finish line is on the right so I want the ball to move to the right 

If you create the ball in the same position as the rectangle it will be force moved somewhere else by the physics engine.  That could be what you’re seeing.

There not positioned in the same place :

-- create image of a ball local ball = display.newCircle( display.contentCenterX, display.contentCenterY - 150, 10) ball.x = 100 ball.y = 200 physics.addBody(ball, "dynamic", {radius=10, bounce = 0.1, density=.1}) ball:setFillColor( 1.5, 0.2, 0.2 ) ball:setStrokeColor( 0, 0, 5 ) ball.isBullet = true ball:applyLinearImpulse( 0, 100 \* ball.mass, ball.x, ball.y )

local myRectangle = display.newRect( display.contentCenterX, display.contentCenterY, 70, 15 ) myRectangle:setFillColor( 0.5, 0.2, 0.2 ) physics.addBody(myRectangle, "static", { friction = 2, density=5})