Explanation regarding collisions - CodeandWeb Physics editor

Hi Andreas,

Thanks for your input.

I think you misunderstood me.

Ball is the dynamic object that collides with the obstacle (static object).

I am using Physics Editor only for the obstacle (not for the ball).

I am initializing physics shape created by Physics Editor for the obstacle - please see my first post in this thread.

Like this:

local  obstacle = display.newImageRect(randomObstacle.img, randomObstacle.wi, randomObstacle.he)        obstacle.x = centerX        obstacle.y = math.random(screenHeight\*0.1, screenHeight\*0.9)        obstacle.typ = "obstacle" --- .nam is just a string like "obstacle24", used to identify specific obstacle       physics.addBody(obstacle, "static", physicsData:get(randomObstacle.nam), {density=1.0, friction=0.2, bounce=0 }) 

I think I have it.

When you call physics.addBody, you pull in the data for randomObstacle.nam. This includes radius, density, friction, bounce etc which are set the editor. So this creates the ‘inner circle’ physics object.

[lua]

physics.addBody(obstacle, “static”, physicsData:get(randomObstacle.nam)

   – CIRCLE PHYSICS OBJECT CREATED

[/lua]

You then added this code:

[lua]

, {density=1.0, friction=0.2, bounce=0 }

– RECTANGLE PHYSICS OBJECT CREATED

[/lua]

Which creates another rectangular physics object the size of the obstacle image.

So I think the code should just be:

[lua]

physics.addBody(obstacle, “static”, physicsData:get(randomObstacle.nam))

[/lua]

I am such an idiot!  :smiley:

Thanks Nick!

One last question please.

How to change precreated filter bits on the fly (later on)?

-- This file is for use with Corona(R) SDK -- -- This file is automatically generated with PhysicsEdtior (http://physicseditor.de). Do not edit -- -- Usage example: --                local scaleFactor = 1.0 --                local physicsData = (require "shapedefs").physicsData(scaleFactor) --                local shape = display.newImage("objectname.png") --                physics.addBody( shape, physicsData:get("objectname") ) -- -- copy needed functions to local scope local unpack = unpack local pairs = pairs local ipairs = ipairs local M = {} function M.physicsData(scale)       local physics = { data =       {                         ["spike1"] = {                                                                                 {                     pe\_fixture\_id = "", density = 2, friction = 0.30000000000000004, bounce = 0.20000000000000001,                     filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },                     radius = 17.000                     }                                                     }                   } }         -- apply scale factor         local s = scale or 1.0         for bi,body in pairs(physics.data) do                 for fi,fixture in ipairs(body) do                     if(fixture.shape) then                         for ci,coordinate in ipairs(fixture.shape) do                             fixture.shape[ci] = s \* coordinate                         end                     else                         fixture.radius = s \* fixture.radius                     end                 end         end             function physics:get(name)             return unpack(self.data[name])       end       function physics:getFixtureId(name, index)                 return self.data[name][index].pe\_fixture\_id       end             return physics; end return M

I am aiming at this line:

filter = { categoryBits = 1, maskBits = 65535, groupIndex = 0 },

 

You could create a table that holds over-ride parameters.

[lua]

local override = {{spike1 = {categoryBits = 2, maskBits = 12345, groupIndex = 1}}}

[/lua]

Then check this table before you add the physics body.

[lua]

local data = physicsData:get(randomObstacle.nam)

if override[randomObstacle.nam] ~= nil then

  data.filter = override[randomObstacle.nam]

end

  1. physics.addBody(obstacle, “static”, data)

[/lua]

 

If you need to do this to an already created obstacle, you’ll need to removeBody and then immediately addBody again.

  1.