Only part of object is able to collide with other objects

840b6243522e72d887a3cb269e60a274.png

The 3 ball object is actually a picture. I don’t understand why only part of it is capable of colliding with the wall on the right. You can see in the picture that the top ball is the only one highlighted when using physics.setDrawMode( “hybrid” )

Here is the code

local playerFile = “sprites/char.png”

local player1 = display.newImage( playerFile , display.actualContentWidth, display.actualContentHeight)

player1.x = display.contentCenterX

player1.y = 200 --400

local player1Outline = graphics.newOutline( 0, playerFile )

–player1.isBullet = true

physics.addBody( player1, “dynamic”, { outline=player1Outline } )

reposting.

I don’t see any bodies on the circles.

I’m not really clear on where the bodies are versus where you want them in that picture.

Make a mini project that demonstrates the problem. Zip it up, and attach it here.

That will get more answers as I for one don’t have time to type in the code and fake up my own art to help debug this, but downloading and running a tiny example I can do.

Well, the reason why there are no physics bodies elsewhere is that of the outline you provided and the fact you only added one physics body.

@sdktester15 is on to something here.

If you want the ‘balls’ to have bodies, add them individually and give them the same radius as the balls.

I thought it should work because the balls are in 1 image and adding the body would mean the whole image, but I guess I could add them separately.

I wanted to move the character(the 3 balls),which is 1 image and not made individually, and prevent it from moving outside of the screen. If it doesn’t work don’t sweat it, I will make it individual parts.

Here is a tester for you guys

Mini Project File

Mini Project File

Sean, I think you should use a multi-element body here. You can read about them at https://docs.coronalabs.com/api/library/physics/addBody.html#multi-element-body.

Here’s a rough example of what you could do. 

 physics.addBody( player1, "dynamic", { friction=0.2, bounce=0.4, shape={0,-76,8,-68,0,-60,-8,-68} }, { friction=0.2, bounce=0.4, shape={50,34,58,26,66,34,58,42} }, { friction=0.2, bounce=0.4, shape={-50,34,-58,26,-66,34,-58,42} } )

If you replace your current physics body for the player with that, you should see that each of your characters now has a physics shape. You would need to refine the shape further though.

I am not certain if you can use circular shapes in multi-element objects, but you could also consider creating three separate characters and then using joints to weld the characters together. More on joints at https://docs.coronalabs.com/guide/physics/physicsJoints/index.html.

Thanks for the project, but I think you missed my point.

  1. I’m not sure why you put your code in a scene.

  2. You didn’t bother to manage your indentations etc, so the code is hard to read. I stopped after a few lines.

Whatever the case, you’re doing this wrong You can’t use the outline feature to make a consistent body (or I suspect you want three bodies) from an image like that.

A. It only works with single images surrounded by transparency. You have three circles each by themselves. Just won’t work.

B. It only approximates the best body it can. You’ll get a much better body by making your own. In this case, the multi-body suggestion above is spot on.

In the future, please remember when folks ask for code/samples your job is to make it drop-dead easy for them to read and examine your code. Nobody wants to dig through a scene when all the code could have been nicely formatted in main.lua (which is was I expected).

For your reference this is a good starter project example that I use for the basis of my answers to forums posts:
https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/askEdStarter.zip

My answers (>400 full code answers by now): https://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd

If I seem like I’m being harsh, please don’t take it that way.

You are very welcome here and I appreciate the effort you put into the example. I just want to get a little more next time you ask for help. My time is ever-more precious, but I want to help when possible.

Cheers and happy developing!

Why make a picture of these circles when you can just make them with code?

local circle = display.newCircle(100, 100, 20)

Then just add physics bodies to each individual circle with physics.addBody, no outline needed. :slight_smile:

Hello guys, thank you for spending time to help me. I appreciate all of your answers. I know I could just make the circles and bodies separately, but for what I need it to do, it is easier for me to just make it a single image. I have some other methods and ideas in mind that will probably make it work. What roaminggamer pointed out is exactly what I needed to know.

Sorry about my coding if you could not figure out what was going on. I am just a noob

A. It only works with single images surrounded by transparency. You have three circles each by themselves. Just won’t work.

B. It only approximates the best body it can. You’ll get a much better body by making your own. In this case, the multi-body suggestion above is spot on.

The biggest issue with this is that Corona’s built-in circles look like they were drawn on a ZX81…

[quote=“Blex,post:11,topic:348225”]

Why make a picture of these circles when you can just make them with code?

local circle = display.newCircle(100, 100, 20)

Then just add physics bodies to each individual circle with physics.addBody, no outline needed. :slight_smile: [/quote]

@nick_sherman - Go retro! :slight_smile:

Yeah, that’s true…

reposting.

I don’t see any bodies on the circles.

I’m not really clear on where the bodies are versus where you want them in that picture.

Make a mini project that demonstrates the problem. Zip it up, and attach it here.

That will get more answers as I for one don’t have time to type in the code and fake up my own art to help debug this, but downloading and running a tiny example I can do.

Well, the reason why there are no physics bodies elsewhere is that of the outline you provided and the fact you only added one physics body.

@sdktester15 is on to something here.

If you want the ‘balls’ to have bodies, add them individually and give them the same radius as the balls.

I thought it should work because the balls are in 1 image and adding the body would mean the whole image, but I guess I could add them separately.

I wanted to move the character(the 3 balls),which is 1 image and not made individually, and prevent it from moving outside of the screen. If it doesn’t work don’t sweat it, I will make it individual parts.

Here is a tester for you guys

Mini Project File