Corona SDK Physics goes on and off while object is in motion -


below main file. happening collision working when "rect" object not moving move rect object, collision stops taking affect. think knows colliding not (like interaction objects @ all). have thoughts, why happening? , how fix it?

local physics = require("physics") ; physics.start() ; physics.setgravity( 0,0 ) ;  physics.setdrawmode( "debug" ) display.setstatusbar( display.hiddenstatusbar ) math.randomseed( os.time() )  physics.setvelocityiterations(10); physics.setpositioniterations(20);   --set references , other variables local ox, oy = math.abs(display.screenoriginx), math.abs(display.screenoriginy) local cw, ch = display.contentwidth, display.contentheight  --set collision filters local screenfilter = { categorybits=2, maskbits=1 } local objfilter = { categorybits=1, maskbits=14 } local fieldfilter = { categorybits=4, maskbits=1 } local magnetfilter = { categorybits=8, maskbits=1 }  --set initial magnet pull local magnetpull = 0.25  --set world , background local screenbounds = display.newrect( -ox, -oy, display.contentwidth+ox+ox, display.contentheight+oy+oy ) screenbounds.name = "screenbounds" screenbounds.isvisible = false ; physics.addbody( screenbounds, "static", { issensor=true,     filter=screenfilter } )   local function newpositionvelocity( object )     local math_random = math.random         local side = math_random( 1,4 ) ; local posx ; local posy ; local velx ; local vely  if ( side == 1 or side == 3 )     posx = math_random(0,display.pixelheight)     velx = math_random( -10,10 ) * 5     if ( side == 1 ) posy = -oy-40 ; vely = math_random( 8,18 ) * 16     else posy = display.contentheight+oy+40 ; vely = math_random( 8,16 ) * -16     end else     posy = math_random(0,display.pixelwidth)     vely = math_random( -10,10 ) * 5     if ( side == 4 ) posx = -ox-40 ; velx = math_random( 8,16 ) * 16     else posx = display.contentwidth+ox+40 ; velx = math_random( 8,16 ) * -16     end end object.x = posx ; object.y = posy object:setlinearvelocity( velx, vely ) object.angularvelocity = math_random( -3,3 ) * 40 object.alpha = 1  end  local rect = display.newrect(100,100,100,60); local offset = 250 rect.x = cw/2; rect.y = ch/2-offset; --rect.xreference = 40; rect.yreference = offset;    local function objectcollide( self, event ) local othername = event.other.name print(event.other.name);  local function ondelay( event )     local action = ""     if ( event.source ) action = event.source.action ; timer.cancel( event.source ) end      if ( action == "makejoint" )         self.hasjoint = true         self.touchjoint = physics.newjoint( "touch", self, self.x, self.y )         self.touchjoint.frequency = magnetpull         self.touchjoint.dampingratio = 0.0         self.touchjoint:settarget( 512, 384 )     elseif ( action == "leftfield" )         self.hasjoint = false ; self.touchjoint:removeself() ; self.touchjoint = nil     else         if ( self.hasjoint == true ) self.hasjoint = false ; self.touchjoint:removeself() ; self.touchjoint = nil end         newpositionvelocity( self )     end end  if ( event.phase == "ended" , othername == "screenbounds" )     local tr = timer.performwithdelay( 10, ondelay ) ; tr.action = "leftscreen" elseif ( event.phase == "began" , othername == "magnet" )     transition.to( self, { time=400, alpha=0, oncomplete=ondelay } ) elseif ( event.phase == "began" , othername == "field" , self.hasjoint == false )     local tr = timer.performwithdelay( 10, ondelay ) ; tr.action = "makejoint" elseif ( event.phase == "ended" , othername == "field" , self.hasjoint == true )     local tr = timer.performwithdelay( 10, ondelay ) ; tr.action = "leftfield" end   end    local function setupworld()  i=1, 20     local obj = display.newcircle(0,0, 12 )     physics.addbody( obj, "dynamic", { bounce=.3, radius=12, density = .2 --[[,filter=objfilter]] } )     obj. isbullet = true;             newpositionvelocity( obj )     obj.hasjoint = false     obj.collision = objectcollide ; obj:addeventlistener( "collision", obj ) end  local field = display.newcircle(cw/2, ch/2, 320);      field.alpha = 0.2; field.name = "field"; field.x = display.contentcenterx ; field.y = display.contentcentery; physics.addbody( field, "static", { issensor=true, radius=320, filter=fieldfilter });  magnet = display.newcircle(cw/2, ch/2, 40 ) magnet.name = "magnet" magnet.x = display.contentcenterx ; magnet.y = display.contentcentery physics.addbody( magnet, "static", { bounce=0, radius=40, filter=magnetfilter } )    end   setupworld()  physics.addbody(rect,"kinematic", { bounce = 1, density = 1})    deg = 0.0;  prevy = 0;  local function ontouch(event)  if event.phase == "began"   prevy = event.y end if (deg<=360)   deg=0; end  if(event.y >= prevy)    deg = deg + 10; elseif(event.y <= prevy)    deg = deg -10; end   prevy = event.y  rect:rotate(deg);  end   runtime:addeventlistener("touch", ontouch); 

kinematic bodies don't generate collisions. needs dynamic.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -