Bounding object for physics objects aka bodies

Hi,
For an object to display real life physics, we can just use physics.addBody, but if we do not have a bounding boundary, the object just falls off the screen. Can this bounding boundary be a path? or a Bitmap/Mask?

What is it that stops the object from falling out of the screen… namely static or ground object. Can I replace that object with an invisible path?

cheers,

Jayant C Varma [import]uid: 3826 topic_id: 3164 reply_id: 303164[/import]

Use a vector object or an image, im using groups as well but there may be issues with that.

Dont use paths, I read somewhere else they dont support the physics well.

You can set the object alpha to zero and the collisions still work.

You can also have a small image and manually add a larger collision boundary. [import]uid: 5354 topic_id: 3164 reply_id: 9296[/import]

Just use a rect without setting the color. [import]uid: 5712 topic_id: 3164 reply_id: 9354[/import]

Hi, Thanks for the comments, but my issues remains. Let me try to re-iterate it.

I have a complex shape( not one that can be easily defined in rect or a series of rects, but is a complex combination of many such primitives)

This is in the form of a bitmap, now I tried loading he bitmap from 0,0 to 320,480 as the background and then on top of that I add a physics body, the first thing it does is it zooms off screen to the right, quite odd, as a physics body should move downwards not to the right. So, I guess I can safely state that an image cannot be used.

Now If I need this complex shape, can I use a polygon with a series of lines? Would a physics body use a series of lines as a bounding boundary? I will be trying it out too, but was wondering if I get some answers before I spend time on it experimenting. When you say a vector image can be used, so this should work, right?

One comment suggested setting a collision boundary, what command allows me to set a collision boundary?

What are the parameters that set interact with a physics body? What shall restrict its movement ans what shall let it pass through?

cheers,

Jayant C Varma [import]uid: 3826 topic_id: 3164 reply_id: 9375[/import]

A quick update, I read at http://developer.anscamobile.com/forum/2010/10/26/ball-passes-through-instead-bouncing#comment-9015 that lines cannot be used as bounding bodies. so… :frowning: [import]uid: 3826 topic_id: 3164 reply_id: 9376[/import]

Hey Jayantv

I think you are getting a bit confused!

You cant use vector lines as I stated, called them paths. You can use images, groups, sprites and vector objects.

If you are making a complex shape then you can combine many collison polygons into one big shape. Think about how a 3d object is constructed out of triangles or quads.

If its shooting off to the right maybe your gravity is set in the wrong direction, are you using landscape? [import]uid: 5354 topic_id: 3164 reply_id: 9378[/import]

Hi Matthew,
I’ll try not to get confused.

The image is a full screen image as the first layer (hence at the back) a full sizes 320x480 image, I have hidden the statusbar so i get full size. The orientation is default, which means it is Portrait. At first, I had the same thoughts as you had, is the gravity set to a different setting? so I set the gravity at the start and ensured that it is not changed. It is set to (0,9.8) so I expect the object to fall downwards.

A code snippet is attached

[code]
local image
image = display.newImage(“game-back.png”,0,0)

rect = display.newRect(160,260,10,10) – A spot that is supposedly void (Alpha)
rect:setFillColor(0,255,0)

physics.addBody(rect,{friction=0.0, bounce=0.5})
physics.addBody(image,“static”,{friction=0.0, bounce=0.5})

local x1,y1
x1,y1 = physics.getGravity()
print (x1 … ", " … y1)
[/code] [import]uid: 3826 topic_id: 3164 reply_id: 9380[/import]

Not in a position to run the code but trying to visualise it.

You are adding a background image, full screen, and setting it to static. So in essence its a wall. The whole screen is one big wall.

You are then adding a smaller rectangle, setting it to dynamic and placing it over the wall.

In my mind you are inserting an object inside another object and as thats not possible the wall forces the object out of itself. Probably why its shooting off to the right. At this point I dont think gravity would be in play as the internal collision forces are whats acting on the dynamic object. [import]uid: 5354 topic_id: 3164 reply_id: 9381[/import]

Hi Matthew,
Thanks for that off the top of your hear glance at the code response. If the object was statis, it is treated as a wall, now what would be the proper attributed that might be applied to the object? ground? By doing so, the image dropped down off the screen along with the object :frowning:

If I do not make the image a body, then the object treats the image like a backdrop and goes about doing it’s stuff, falling off the screen.

cheers,

Jayant C Varma [import]uid: 3826 topic_id: 3164 reply_id: 9382[/import]

Static is correct, walls should move or be effected by gravity.

The problem here is that you are setting the entire screen ( as the image is the screen size ) as a collisions object. This means that you cant have any other dynamic objects on screen as a dynamic object cannot exist inside a static object.

Its like this, imagine hitting your hand against a wall, it bounces back. The setup you are trying to do places your hand inside the wall as its starting point. This cannot happen in reality, your hand cannot exist inside brick. The same principle acts here, physical objects cannot occupy the same space so the wall expels the object until they no longer occupy the same space.

What you need to do it define the collision boundary manually, placing it somewhere near the bottom of the screen (turn on hybrid mode) rather than letting Corona use the whole image as a boundary.

local wall_1 = { x1,y1 , x2,y2 , x3,y3 , x4,y4 }

physics.addBody(image,“static”, {friction=0.0, bounce=0.5} , shape=wall_1 )

The wall x1, y1. Work out the co-ordinates, in a clockwise manner (from object reference point). Hybrid mode will show you what you are drawing and if Corona crashes your collision box coordinates are not correct. [import]uid: 5354 topic_id: 3164 reply_id: 9383[/import]