Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Only part of object is able to collide with other objects
Started by sean.sath Jul 30 2018 11:26 AM

14 replies to this topic

Best Answer roaminggamer , 31 July 2018 - 09:53 AM

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

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

sean.sath

[GLOBAL: userInfoPane.html]
sean.sath
  • Observer

  • 15 posts
  • Corona SDK

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 } )


[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,093 posts
  • Corona SDK

reposting.

 

 

I don't see any bodies on the circles.



[TOPIC: post.html]
#3

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,093 posts
  • Corona SDK

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.



[TOPIC: post.html]
#4

sdktester15

[GLOBAL: userInfoPane.html]
sdktester15
  • Corona Geek

  • 1,195 posts
  • Corona SDK

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.



[TOPIC: post.html]
#5

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,093 posts
  • Corona SDK

@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.



[TOPIC: post.html]
#6

sean.sath

[GLOBAL: userInfoPane.html]
sean.sath
  • Observer

  • 15 posts
  • Corona SDK

@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



[TOPIC: post.html]
#7

sean.sath

[GLOBAL: userInfoPane.html]
sean.sath
  • Observer

  • 15 posts
  • Corona SDK

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.

Mini Project File



[TOPIC: post.html]
#8

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 189 posts
  • Corona SDK

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.



[TOPIC: post.html]
#9

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,093 posts
  • Corona SDK

  Best Answer

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

[TOPIC: post.html]
#10

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,093 posts
  • Corona SDK

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!

[TOPIC: post.html]
#11

sdktester15

[GLOBAL: userInfoPane.html]
sdktester15
  • Corona Geek

  • 1,195 posts
  • Corona SDK

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. :)



[TOPIC: post.html]
#12

sean.sath

[GLOBAL: userInfoPane.html]
sean.sath
  • Observer

  • 15 posts
  • Corona SDK

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.



[TOPIC: post.html]
#13

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,554 posts
  • Corona SDK

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

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. :)


[TOPIC: post.html]
#14

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,093 posts
  • Corona SDK

@nick_sherman - Go retro! :)

[TOPIC: post.html]
#15

sdktester15

[GLOBAL: userInfoPane.html]
sdktester15
  • Corona Geek

  • 1,195 posts
  • Corona SDK

Yeah, that's true...




[topic_controls]
[/topic_controls]