Collision Detection Issue

So I am having issues with my collision detection. I am using the Beebegames.lua class.

Here is my code that creates the chopper:

  
 chopper = newObject( {"chopper.png"}, 60, 38, sw, display.contentHeight+40, nil, nil, 1, playerStuff)  
 chopper.name = "chopper"  
 physics.addBody( chopper, "kinematic", {density=0.2, friction=0.2, bounce=0.1 })  
  
 transition.to( chopper, {delay=2000, time=2000, transition=easing.outExpo, y=yPosition})  
  
  
 local onLocalCollision = function ( self, event)  
 if ( event.phase == "began" ) and ( event.other.name == "building" ) then  
  
 print("Indeed Yes!")  
 chopper:destroy()  
 chopper = nil  
  
 end  
  
 end  
  
 chopper.collision = onBuildingCollision  
 chopper:addEventListener( "collision", chopper)  
  

Here is the code I use to make some sensors to detect the collision

  
 buildingCollision1 = display.newRect( background, 0, 0, 22, 480)  
 buildingCollision1.alpha = 0  
 buildingCollision1.name = "building"  
 physics.addBody( buildingCollision1, { isSensor=true })  
  
 buildingCollision2 = display.newRect( background, 298, 0, 22, 480)  
 buildingCollision2.alpha = 0  
 buildingCollision2.name = "building"  
 physics.addBody( buildingCollision2, { isSensor=true })  
  

So basically on the device and simulator it doesn’t detect the collision, anyone see what im doing wrong? Thanks a lot in advance!

-Kyle

Oh and Merry Christmas!! [import]uid: 9968 topic_id: 4695 reply_id: 304695[/import]

I figured it out and found a new issue.

Line 19 of my code needed to be changed to onLocalCollision instead of onBuildingCollision.

Now it is having a problem with the chopper:destroy() function. This is probably going to be a question more or less for John Beebe and his class.

Its telling me in the console that destroy is a nil, but I have declared your Beebegames.lua file! Any suggestions?

Thanks a lot! [import]uid: 9968 topic_id: 4695 reply_id: 14868[/import]

That’s really strange, I created a test project using the BeebeGames class, added a physics object, and then called myObject:destroy() after 10 seconds… everything worked with no errors.

Perhaps in your onLocalCollision function, instead of calling chopper:destroy() and chopper = nil … try calling self:destroy() and self = nil

That’s where I’d start.

If that doesn’t get you anywhere, then try commenting out your collision function, and instead calling chopper:destroy() on a timer event (after say, 5 seconds). If it allows you to call destroy(), then it must be a problem within the code you commented out.

If it’s not your collision listener, then get it to where the destroy() function works, and then slowly add code and test until you narrow down what’s causing the problem.

I’ve confirmed that physics bodies added to display objects created with the newObject() function do in fact work, and can be added and that destroy() can be called.

If you absolutely CANNOT get the destroy() function to work, then that’s okay. Just call chopper:removeSelf(); chopper = nil --> that should get the job done.

Hope that helps! [import]uid: 7849 topic_id: 4695 reply_id: 14874[/import]

Thanks for your response John, I will try all of your suggestions and check back in. I have been playing with it for quite some time so hopefully I can get it working because this class is amazing!

Thanks a lot!

-Kyle [import]uid: 9968 topic_id: 4695 reply_id: 14876[/import]

Thanks Kyle! Glad you like it. Did you be sure to get version 1.3 that was released just yesterday (lots of new timer features)? [import]uid: 7849 topic_id: 4695 reply_id: 14877[/import]

@Kyle: I discovered a major bug with my BeebeGames Class and the physics engine. The latest version (1.5) should fix all of your issues related to physics bodies, etc.

You can get it here:
http://developer.anscamobile.com/code/beebegames-class [import]uid: 7849 topic_id: 4695 reply_id: 15050[/import]

Awesome! Thanks a lot for doing what you do man! I will test it out and see how it helps!

-Kyle [import]uid: 9968 topic_id: 4695 reply_id: 15051[/import]