Physics Outline + Collision Filter Issues

 local shipOutline = graphics.newOutline( 2, sheet, sheetInfo:getFrameIndex(shipName)) local shipCollisionFilter = { categoryBits = bitTable.ship, maskBits = bitTable.enemyLaser } local shipBodyElement = { filter = shipCollisionFilter, outline = shipOutline} physics.addBody( ship.shipImage, "static", shipBodyElement)

I am using this code to try to give my ship a physics outline instead of just a square. I am finding it difficult to mix it with my existing collision filter code, the ship no longer collides with enemy lasers like it used to. Where am I going wrong here?

Have you examined the resulting physics body?  

Set drawmode to hybrid and see if the shape is what you think it should be.  Outline is not guaranteed to give a perfect body nor will it always match the graphic shape.

https://docs.coronalabs.com/daily/api/library/physics/setDrawMode.html

Yes, I have been looking at the body in hybrid mode and it shows up as a physics body. I don’t get collisions anywhere on the object though.

You could get and use “Physics editor”. After you get the hang of it it’s really nice to have. There is a 7 day trial.

I found that for small things like ships it’s very easy to use because you can just get the shape code from the other file and use it in your code instead of reading files.

–SonicX278

I saw the physics editor as an option, I was discouraged when I saw you have to pay for it. Is there anything you can see wrong with the code I have?

Oh ya i understand. I always get that “Ughhh” feeling when i find a good tool and then find out that i have to pay haha … I can’t really say as iv’e never used graphics.newOutline. Sorry.

–SonicX278

You guys aren’t encouraging me to help here… 

  1. You shouldn’t complain about paying a small amount to use a tool that saves you a lot of work.

  2. I’m not pleased to see comments to the effect, “I found a way not to pay…”

All I was saying was that I realized that Corona has a built in function to do the same thing so want want to learn how to use that. The shape that it is drawing seems to be correct enough for me, it is just not detecting collisions anymore.

I’d try these debug steps:

Test 1 - Make the body with no filters, and test it.

  • WORKS -  The filter is wrong.  Evaluate your filter settings and try again.
  • FAILS - Move on the test 2

Test 2 - Make the body with your filter and a default shape (no outline).

  • WORKS -  The outline is goofed up.
  • FAILS - Move on the test 3.

Test 3 - Make a small (very simple) test bench:

  • main.lua - Write a small sample using your filter settings, outline, and collision listener.  Demonstrate it fails.
  • config.lua - Basic iPhone 4 size setup and letterbox scaling
  • build.settings - Landscape or portrait orientation only (whatever suits your example).
  • include outline asset and other images used in example.

Run the sample.  If it fails, use this to file a bug, but share a link to a ZIP containing all the above here too so others can help debug.

-Ed

There is another alternative here.  Don’t hand calculate filters.  Use my collision calculator instead.  Its free and much easier than calculating filters.

https://store.coronalabs.com/plugin/collision-calculator

If you don’t want to use it as a plugin, you can find the same code in SSK:

Ya sorry @roaminggamer. That was some time ago I did that on my laptop. I built my own pc now and I bought the product like a week ago. When I need something i do buy it now as I do understand that as a developer I get why devs want a small fee for their hard work. --SonicX278

@mpkostech What I do is make a new project and put code in little by little till you find what’s wrong. --SonicX278

My problem is that Corona completely crashes and closes when I use the actual ship group (which is what I do throughout my code and I get expected results). When I replace the ship group with just the ship’s image (as in the code below, Corona does not crash but there is no collision:

function Ship:new(X, Y) local ship = display.newGroup() ship.x = X ship.y = Y ship.objectType = "ship" ship.health = shipHealth ship.shipLaserGroup = display.newGroup() moveGroup:insert(ship.shipLaserGroup) ship.shipImage = display.newImage(sheet,sheetInfo:getFrameIndex(shipName)) ship.shipImage.xScale = 0.7 ship.shipImage.yScale = 0.7 ship:insert(ship.shipImage) local group = display.newGroup() local particle = pex.load("Exhaust/exhaust.pex","Exhaust/texture.png") local emitter = display.newEmitter(particle) emitter.x = ship.shipImage.x emitter.y = ship.shipImage.y + ship.shipImage.height/2 ship:insert(emitter) local shipOutline = graphics.newOutline( 2, sheet, sheetInfo:getFrameIndex(shipName)) local shipCollisionFilter = { categoryBits = bitTable.ship, maskBits = bitTable.enemyLaser } physics.addBody( ship.shipImage, "static", {filter = shipCollisionFilter, outline = shipOutline}) return ship end

Should I be reporting this as a bug? Corona consistently crashes when I try to use a group as a physics body in conjunction with an outline.

@mpkostek,

  1. Forums etiquette note - You should only use the quote option to respond to a small part of someone’s post like this:

If you don’t need to quote a specific part of the persons response and you want to address that person in your addition to the forum thread do this:

@persons name,

Say what you want here…

Re-quoting every response just wastes space and is hard tor read with no addition of meaning or context.

  1. To answer your question.  Yes, file a bug, but make a very small test bench demonstrating the issue and submit that as a bug.  Don’t expect the Corona staff to write the example themselves.

-Ed

Have you examined the resulting physics body?  

Set drawmode to hybrid and see if the shape is what you think it should be.  Outline is not guaranteed to give a perfect body nor will it always match the graphic shape.

https://docs.coronalabs.com/daily/api/library/physics/setDrawMode.html

Yes, I have been looking at the body in hybrid mode and it shows up as a physics body. I don’t get collisions anywhere on the object though.

You could get and use “Physics editor”. After you get the hang of it it’s really nice to have. There is a 7 day trial.

I found that for small things like ships it’s very easy to use because you can just get the shape code from the other file and use it in your code instead of reading files.

–SonicX278

I saw the physics editor as an option, I was discouraged when I saw you have to pay for it. Is there anything you can see wrong with the code I have?

Oh ya i understand. I always get that “Ughhh” feeling when i find a good tool and then find out that i have to pay haha … I can’t really say as iv’e never used graphics.newOutline. Sorry.

–SonicX278