[SOLVED] Physics/Collision Problem

Hello Community, I need the ball doesn’t collide with other balls, and if I add Right and Left Walls, when the balls collides with them, they get remove. Here’s my code:

[code]
–Hide Status Bar
display.setStatusBar ( display.HiddenStatusBar )

–Physics Setup
local physics = require “physics”
physics.start ()
physics.setGravity ( 0, 9.8 )
physics.setScale ( 80 )
physics.setDrawMode ( “normal” )

–Variables
local wScreen = display.contentWidth
local hScreen = display.contentHeight
local mRandom = math.random
local staticObject = { density = 2, friction = 0.3, bounce = 0.4 }
local ballObject = { density = 0.8, friction = 0.3, bounce = 0.6, radius = 12 }

–Objects
local background
local ball
local floor

–Functions
local startScreen = {}
local spawnBalls = {}
local removeBalls = {}

–Main Function
local function main ()
startScreen ()
end

–Initial Screen
function startScreen ()
background = display.newImage ( “background.png” )
background:setReferencePoint ( display.CenterReferencePoint )
background.x = wScreen * 0.5
background.y = hScreen * 0.5
floor = display.newRect ( 0, hScreen, wScreen, 1 )
physics.addBody ( floor, “static”, staticObject )
end

–Spawn Ball
function spawnBalls:tap ()
ball = display.newImage ( “Ball.png” )
ball:setReferencePoint ( display.CenterReferencePoint )
ball.x = mRandom ( 40, wScreen - 40 )
ball.y = mRandom ( 40, hScreen - 40 )
physics.addBody ( ball, ballObject )
end
–Listener
Runtime:addEventListener ( “tap”, spawnBalls )

main () [import]uid: 81091 topic_id: 17923 reply_id: 317923[/import]

Please take a look at this tutorial, it will help you understand the basics of collision detection; http://techority.com/2011/06/19/corona-for-newbies-part-4-physics/

Peach :slight_smile: [import]uid: 52491 topic_id: 17923 reply_id: 68545[/import]

The answer is basically there.

PLay with it some more, hit up techority.com like peach said and tear it apart.

You will find that you are missing a few key items.
Let us know how it works out :slight_smile:

ng [import]uid: 61600 topic_id: 17923 reply_id: 68683[/import]

Ok guys, I’ll take a look at the tutorial.

Thanks! [import]uid: 81091 topic_id: 17923 reply_id: 68935[/import]

Hey, great tutorial, so easy to understand, but I need something else, how can I make that two objects don’t collide between them and collides with another object? [import]uid: 81091 topic_id: 17923 reply_id: 68939[/import]

“how can I make that two objects don’t collide between them and collides with another object”

What does this mean? Are you trying to have 2 objects pass through another object THEN produce a collision, or what are you trying to do?

Have you ever tried sensors?

Sensors are handy :slight_smile:
go to techority.com and search “sensor” you will find a tutorial on it.

It’s not going to directly answer your question, but you can be creative with sensors! In Peach’s example, the color changes when one object touches another. Since we are just talking about a function - the changing color can be changed to a collision event, or a score, or a timer…pretty much anything.
That’s what I learned - it’s not knowing everything, it’s applying concepts that were written for something else to a new concept I’m working on. Once you got that down, you will start seeing new things :slight_smile:

I’ll check back in later, see what you come up with.
[import]uid: 61600 topic_id: 17923 reply_id: 68949[/import]

Sounds like you’re talking about a collision filter? Or you could use a sensor that switches to static/dynamic on a pre collision event with the object you want it colliding with.

Check out the Physics APIs a little more :wink:

Peach :slight_smile: [import]uid: 52491 topic_id: 17923 reply_id: 68952[/import]

Yeah, I’m looking for a collision filter, I found what I was needing, thanks for your help Peach; and Nicholas, that info about sensors is so useful for something that I should do, thanks too. [import]uid: 81091 topic_id: 17923 reply_id: 68983[/import]

Glad to hear it :slight_smile:

Peach [import]uid: 52491 topic_id: 17923 reply_id: 69063[/import]