Custom physics shapes disables bounce

Made a code with regular walls, like:

local rightWall = display.newRect( display.contentWidth - 10, 0, 10,display.contentHeight )   
  
physics.addBody(rightWall, "static", {density = 1.0, friction = 0, bounce = 1, isSensor = false})  

BUT! when i make a wall with a custom shape like:

wall1Shape = {-128,-128, 127,-128, 127,-84, 71,-77, 8,-33, -13,11, -80,62, -85,123}  
  
local rightWall = display.newRect( display.contentWidth - 10, 0, 10,display.contentHeight )   
  
physics.addBody(rightWall, "static", {density = 1.0, friction = 0, bounce = 1, isSensor = false, shape=wall1Shape})  

With regular wall the ball bounces, but with custom shape the ball sticks to the wall… why is that?

(i have tried to do the custom coordinates clockwise and anticlockwise)
[import]uid: 134049 topic_id: 24245 reply_id: 324245[/import]

Hey Jonathan,

I just tried your code with a ball (0 bounce on the ball) that dropped onto the top of your custom shape and it bounced just fine.

Can you tell me what version of Corona you are using? I’m using 704 but can retest with whatever you are currently running.

Peach :slight_smile: [import]uid: 52491 topic_id: 24245 reply_id: 97959[/import]

Hey Peach, What i forgot to mention is that i have a “Nonstop bounce ball”

With this code:

ball = display.newCircle( 0, 0, 15 )  
ball.x, ball.y = 200, 200  
physics.addBody(ball, "dynamic", {density = 1, friction = 0, bounce = 1, isSensor = false, radius = 15})  
ball.isBullet = true  
ball:applyForce(100, 10)   
local function resetLinearVelocity(event)  
 local thisX, thisY = ball:getLinearVelocity()  
  
 if thisY == 0 then  
 thisY = -ball.lastY  
 end   
  
  
 if thisX == 0 then  
 thisX = -ball.lastX  
 end   
 ball:setLinearVelocity(thisX, thisY)  
 ball.lastX, ball.lastY = thisX, thisY   
end   
  
local function onCollision(event)  
 LetterChannel = audio.play( Esound, { channel=1 })  
 timer.performWithDelay(0, resetLinearVelocity)  
 end   
ball:addEventListener("collision", onCollision)   

I tried to set 0 bounce on the ball without success. [import]uid: 134049 topic_id: 24245 reply_id: 97967[/import]

Can you provide full plug and play code that shows the issue? (This is broken into parts, obviously, and I don’t know your gravity settings or the like either.)

So far, as best I can tell, bounce is absolutely fine - I expect this is a problem in the code.

The delay of 0 on your reset linear velocity function is a bit odd too - why is it in a timer? [import]uid: 52491 topic_id: 24245 reply_id: 98174[/import]

This issue is caused by not adhering to the following custom shape rule :

  1. Your custom shape is limited to 8 points (must be defined in a clockwise direction), if you need more than this use multiple body definitions.
    [import]uid: 84637 topic_id: 24245 reply_id: 98258[/import]

@Danny & @Peach:

I pointed this out in another users thread, but the documentation is not correct and also caused me many hours of confusion when I first started out. See here:

http://developer.anscamobile.com/content/game-edition-physics-bodies#Complex_body_construction

As you can see, the sample creates the shapes in a counter clockwise shape for both roofShape and trunkShape. This also seems like the only example of creating a complex body in the documentation.

[code]
local car = display.newImage(“big_red_car.png”)
roofShape = { -20,-10, 20,-10, 20,10, -20,10 }
hoodShape = { 0,-35, 37,30, -37,30 }
trunkShape = { 0,-37, 37,-10, 23,34, -23,34, -37,-10 }

physics.addBody( car, “dynamic”,
{ density=3.0, friction=0.5, bounce=0.2, shape=roofShape },
{ density=6.0, friction=0.6, bounce=0.4, shape=hoodShape },
{ density=4.0, friction=0.5, bounce=0.4, shape=trunkShape }
)
[/code] [import]uid: 31262 topic_id: 24245 reply_id: 98269[/import]

here is a plug and play code that displays my problem:

local physics = require("physics")  
physics.start()  
physics.setGravity(0, 0)  
physics.setDrawMode( "hybrid" )  
  
Shape1 = {127,126, 95,127, 107,75, 82,16, 86,-51, 81,-98, 88,-130}  
  
local myRectangle = display.newRect(300, 600, 50, 100)  
myRectangle:setFillColor(0, 0, 0, 0)  
  
physics.addBody( myRectangle, "static", {density = 1.0, friction = 0, bounce = 1, isSensor = false, shape=Shape1 } )  
  
ball = display.newCircle( 0, 0, 15 )  
ball.x, ball.y = 100, 200   
physics.addBody(ball, "dynamic", {density = 1, friction = 0, bounce = 1, isSensor = false, radius = 15})  
ball.isBullet = true  
ball:applyForce(200, 20)  
local topWall = display.newRect( 0, 0, display.contentWidth, 10 )  
local bottomWall = display.newRect( 0, display.contentHeight - 10, display.contentWidth, 10 )  
local leftWall = display.newRect( 0, 0, 10, display.contentHeight )  
local rightWall = display.newRect( display.contentWidth - 10, 0, 10, display.contentHeight )  
physics.addBody(topWall, "static", {density = 1.0, friction = 0, bounce = 1, isSensor = false})  
physics.addBody(bottomWall, "static", {density = 1.0, friction = 0, bounce = 1, isSensor = false})  
physics.addBody(leftWall, "static", {density = 1.0, friction = 0, bounce = 1, isSensor = false})  
physics.addBody(rightWall, "static", {density = 1.0, friction = 0, bounce = 1, isSensor = false})  
  
local function resetLinearVelocity(event)  
 local thisX, thisY = ball:getLinearVelocity()  
  
 if thisY == 0 then  
 thisY = -ball.lastY  
 end   
  
  
 if thisX == 0 then  
 thisX = -ball.lastX  
 end   
 ball:setLinearVelocity(thisX, thisY)  
 ball.lastX, ball.lastY = thisX, thisY   
end   
local function onCollision(event)  
 LetterChannel = audio.play( Esound, { channel=1 })  
 resetLinearVelocity()  
 end   
ball:addEventListener("collision", onCollision)   

And im using the latest build 775 [import]uid: 134049 topic_id: 24245 reply_id: 98270[/import]

As far as i know this should be 7 points in a clockwise direction, i even tried it counterclockwise

Shape1 = {127,126, 95,127, 107,75, 82,16, 86,-51, 81,-98, 88,-130}
[import]uid: 134049 topic_id: 24245 reply_id: 98271[/import]

When I plot these points it seems to form some sort of zig zagged shape. What is Shape1 supposed to look like? [import]uid: 31262 topic_id: 24245 reply_id: 98275[/import]

its supposed to be a uneaven cave wall, so the shape should be somewhat zigg zagged, May it be the oddness of my shape that messes with the bounce? [import]uid: 134049 topic_id: 24245 reply_id: 98277[/import]

Yes you can’t do that. You will have to create multiple body shapes to achieve that. [import]uid: 31262 topic_id: 24245 reply_id: 98279[/import]

ah intresting, then i will end up with about 40shapes, but if you want a cave wall its worth it! [import]uid: 134049 topic_id: 24245 reply_id: 98293[/import]

I had this problem.

Use physics editor, you don’t have to worry about the weird rule about going clockwise and swinging a dead chicken and hopping on one leg to make it work. It’s easy to use, and I use it for a level editor, and for all my custom shapes. That whole clockwise limitation is basically non existent. WHY? Because physics editor will auto trace the shape for you and manages the limitation for you automatically… Saves hours of work and guessing! Additionally, the guy who makes it Andreas is awesome with support and always responsive.

It’s free for up to 10 shapes, but if you want to use it commercially you need a license.

www.physicseditor.de

Eh, I guess I sound like a sales guy lol. But it’s my #1 tool, I could not make my current game without it, it would be very very near impossible haha.
If you didn’t want to go that route, then you could write a function and attach a listener for x and y touch events to print out in the terminal, then use the x and y to make the shape. I did that in the beginning, but that is a PAIN IN THE ASS. :slight_smile:
Enjoy!

-Nick [import]uid: 61600 topic_id: 24245 reply_id: 98307[/import]

I also use physics editor and can vouch for it. One of the best tools out there. [import]uid: 31262 topic_id: 24245 reply_id: 98310[/import]