Collision not always detected

I had no problem with the detection until I decided i using more than 1 frame in my animation spritesheet

as soon as i done that even though i set the isSensor = true

sometimes just not detect it.

Has anyone had this issue, and if has can you advice me.

I can only think its because the sprite animation sizes changing but the boundary box is not, and the box2d boundary is set to the right size too as i can see it when i am using hybrid mode.

Its not really to collide just to sense the object ,

But like I said it worked fine when its only 1 frame 

Hi @jollzy,

You’ll probably need to post some code for us to help. We can’t see how you’ve set up your objects, listeners, or anything else.

Thanks,

Brent

this is the animation object

local specialObjectAnimation = {   

    {name = “bomb”, frames = {1,2}, time = 10, loopCount = 0},<—if here I change the frames only to 1(  frames = {1} ) the hole things works

    {name = “boom”, frames = {3,4,5,6}, time = 1600, loopCount = 1}

}

 

here I create the sprite object

 

 options = {

        width = 25,

        height = 40,

        numFrames = 6,

        sheetContentWidth = 76, 

        sheetContentHeight = 81 

    };

    specialObjectSheet = graphics.newImageSheet(“IMG/bomb.png”, options);

 

here I create the specialObject wich contains my animation and adding a dynamyc physic body and enabling the isSensor to true

 

local special = display.newSprite(group, specialObjectSheet, specialObjectAnimation);

    physics.addBody(special, “dynamic”, {bounce = 0, radius = 20, isSensor = true});

    special.angularVelocity = 200;

    special.gravityScale = 0;

    special.isSensor = true;

    special.isHit = false


here is the fraction of the code for the collision event 

 

elseif event.other.name == “special” then

                if event.other.frame == 1 then

                 

                     event.other:pause() <-- pausing the bomb animation

                     event.other:setSequence(“boom”);<-- setting it to the  boom animation

                     event.other:setFrame(3)<-- start frame from 3

                     event.other:play()<— play

                end

            else

But all this should not be any reason not to work I belive this is the frame work

Hi @jollzy,

The first thing I’d try is changing where you assign “name” (= “special”) to your object. This might be causing conflict with the “name” of the sprite sequence, thus it’s skipping the collision because of your conditional logic (event.other.name == “special”). Try setting it to something more descriptive like “objectName” and see what happens.

Brent

Hi Brent,

I am also having problems with collision detection.

Something seems to have changed in the way Corona detects collisions because my game used to work before and now it doesn’t (I’am currently using build 2321, but this problem happens with 2319 and older builds also).

I have a game where my player has to fly through obstacles.

If I use a power-up, my player will fly at high speed through 10 obstacles in a second. 

Now, when I use this power-up my code only detects 1 or 2 obstacles, instead of 10.

I just tested my game with build 2126 and it detects all obstacles properly with my power-up.

Do you know what may be going on?

Jorge

Hi Jorge,

Can you supply more details? Are you using a 3rd-party tool like LevelHelper? We’re investigating some changes that occurred in Box2D and how they might relate to Corona’s physics engine.

Brent

Hi Brent,

The game is a “flappy bird” style game, you can download it here if you want: https://itunes.apple.com/us/app/ice-flap-penguin/id820598401?mt=8&ign-mpt=uo%3D4

I am not using 3rd-party tools.

I use display.newLine to create a sensor every few “centimeters” within the game. When the player touches the sensor, I know that they have passed another obstacle.

The problem happens when I use a power-up that speeds up the player 6 times. The sensors are not triggered. It just flies through.

Perhaps the player’s hit area is small and at that speed it is jumping between the sensor line without touching it … but it works fine with the older build, so something has changed.

Jorge

Hi Jorge,

Are the lines static physics objects? I assume not if they’re moving (unless you do a frame update on them). Lines should not be used for physics objects unless they’re static objects… I believe this has been the case for awhile, and pointed out in the documentation. The easiest solution would be to change them from lines to (thin) rectangles.

Best regards,

Brent

Hi Brent, if I make rectangles at least 4 pixel wide, then the collision is detected at “high speeds”, but it I make rectangle 3 pixels and under, I have the same problems as the lines.

So, I will use that workaround, thank you for the suggestion :slight_smile:

Still, I think collisions should be detected even in thin rectangles, so you may want to check on that.

Jorge

Hi @jollzy,

You’ll probably need to post some code for us to help. We can’t see how you’ve set up your objects, listeners, or anything else.

Thanks,

Brent

this is the animation object

local specialObjectAnimation = {   

    {name = “bomb”, frames = {1,2}, time = 10, loopCount = 0},<—if here I change the frames only to 1(  frames = {1} ) the hole things works

    {name = “boom”, frames = {3,4,5,6}, time = 1600, loopCount = 1}

}

 

here I create the sprite object

 

 options = {

        width = 25,

        height = 40,

        numFrames = 6,

        sheetContentWidth = 76, 

        sheetContentHeight = 81 

    };

    specialObjectSheet = graphics.newImageSheet(“IMG/bomb.png”, options);

 

here I create the specialObject wich contains my animation and adding a dynamyc physic body and enabling the isSensor to true

 

local special = display.newSprite(group, specialObjectSheet, specialObjectAnimation);

    physics.addBody(special, “dynamic”, {bounce = 0, radius = 20, isSensor = true});

    special.angularVelocity = 200;

    special.gravityScale = 0;

    special.isSensor = true;

    special.isHit = false


here is the fraction of the code for the collision event 

 

elseif event.other.name == “special” then

                if event.other.frame == 1 then

                 

                     event.other:pause() <-- pausing the bomb animation

                     event.other:setSequence(“boom”);<-- setting it to the  boom animation

                     event.other:setFrame(3)<-- start frame from 3

                     event.other:play()<— play

                end

            else

But all this should not be any reason not to work I belive this is the frame work

Hi @jollzy,

The first thing I’d try is changing where you assign “name” (= “special”) to your object. This might be causing conflict with the “name” of the sprite sequence, thus it’s skipping the collision because of your conditional logic (event.other.name == “special”). Try setting it to something more descriptive like “objectName” and see what happens.

Brent

Hi Brent,

I am also having problems with collision detection.

Something seems to have changed in the way Corona detects collisions because my game used to work before and now it doesn’t (I’am currently using build 2321, but this problem happens with 2319 and older builds also).

I have a game where my player has to fly through obstacles.

If I use a power-up, my player will fly at high speed through 10 obstacles in a second. 

Now, when I use this power-up my code only detects 1 or 2 obstacles, instead of 10.

I just tested my game with build 2126 and it detects all obstacles properly with my power-up.

Do you know what may be going on?

Jorge

Hi Jorge,

Can you supply more details? Are you using a 3rd-party tool like LevelHelper? We’re investigating some changes that occurred in Box2D and how they might relate to Corona’s physics engine.

Brent

Hi Brent,

The game is a “flappy bird” style game, you can download it here if you want: https://itunes.apple.com/us/app/ice-flap-penguin/id820598401?mt=8&ign-mpt=uo%3D4

I am not using 3rd-party tools.

I use display.newLine to create a sensor every few “centimeters” within the game. When the player touches the sensor, I know that they have passed another obstacle.

The problem happens when I use a power-up that speeds up the player 6 times. The sensors are not triggered. It just flies through.

Perhaps the player’s hit area is small and at that speed it is jumping between the sensor line without touching it … but it works fine with the older build, so something has changed.

Jorge

Hi Jorge,

Are the lines static physics objects? I assume not if they’re moving (unless you do a frame update on them). Lines should not be used for physics objects unless they’re static objects… I believe this has been the case for awhile, and pointed out in the documentation. The easiest solution would be to change them from lines to (thin) rectangles.

Best regards,

Brent

Hi Brent, if I make rectangles at least 4 pixel wide, then the collision is detected at “high speeds”, but it I make rectangle 3 pixels and under, I have the same problems as the lines.

So, I will use that workaround, thank you for the suggestion :slight_smile:

Still, I think collisions should be detected even in thin rectangles, so you may want to check on that.

Jorge