Collision Problems, Filters, Dynamic, Kinematic, OH my!

@giflop and @darkconsole

there are only three option available for physics body (in box2d) all are exposed in corona and they are perfect too fit our any requirement(even some big companies are also using this). if it is not working then it is our fault as box2d has been tested a lot of time and most of game engines are using this. in simple terms it is best but its really some what difficult to understand that

:slight_smile:
[import]uid: 12482 topic_id: 18497 reply_id: 71208[/import]

@rob

i think after changing first line you should not have any probs actually i have just wake up now not even taken tea so sorry if i am wrong

[lua]local staticCollisionFilter = { categoryBits = 1, maskBits = 3 }[/lua]
:slight_smile: [import]uid: 12482 topic_id: 18497 reply_id: 71209[/import]

If I understand collision filters correctly, staticCollisionFilter is known as Bit 1. maskBits = 3, says it will collide with Bit 1 and Bit 2, where the collisionFilter with an ID2 is my actor. (1 + 2 = 3)

Since this is all bit mask, my 3rd filter for the bullets will have to be Bit 4, so if I want bullets (4) to hit the #1 things and not collide with my actor #2, should my mask be a 1? [import]uid: 19626 topic_id: 18497 reply_id: 71212[/import]

yes u have understand that right and your code is perfect dont know why it is not giving collision

for that actually i am using this method for collision filter may be it is helpful for some one

local wall = 1;
local actor = 2;
local bullet = 4;

local wallMask = wall + actor + bullet
local actorMask = wall --it cant collide with each other and bullet
local bulletMask = wall

:slight_smile:
[import]uid: 12482 topic_id: 18497 reply_id: 71221[/import]

I think I have it. Its the same issues the OP is running with. kinematic objects apparently don’t collide with each other. I made the bullets and the enemy dynamic and now they are doing their biz. [import]uid: 19626 topic_id: 18497 reply_id: 71222[/import]

Well, if anyone has any problems similar to me, or wants to be able to direct a dynamic projectile in the direction of a particular point while accounting for gravity, some of my friends with better math skills than my own helped me through it.

Here’s the solution:

local onTouch = function( event )  
 if (event.phase == "began" or event.phase == "moved") and weaponReady then  
  
 local x = event.x - weapon.x  
 local y = event.y - weapon.y  
  
 local gravity = 5  
 local deltaT = 0.033  
 local scaleFact = 30  
  
 local targetTime = 1  
  
 -- mass is density \* area of mudball image in METERS (1 meter = 30 pixels)  
 local mass = 10 \* (3.5/scaleFact)\*(3.5/scaleFact)\*math.pi   
  
 local xForce = x \* mass/(targetTime \* scaleFact \* deltaT)  
 local yForce = ((y/scaleFact) - 0.5 \* gravity \* targetTime \* targetTime) \* mass / (targetTime \* deltaT)  
  
 weapon.bodyType = "dynamic"   
 weapon:applyForce( xForce, yForce, weapon.x, weapon.y )  
  
 end  
end  
  

My failing was as I had expected. I did not properly account for mass (or even begin to calculate it properly)

Cheers! [import]uid: 37122 topic_id: 18497 reply_id: 71223[/import]

Hey Rob & hgvyas123, a quick note to let you guys know that I’ve learned something new by hearing you discuss collision filters. I’m definitely going to learn more about it when I get a chance. It sure sounds like a very useful thing to master.

Edit: Glad to hear you guys figured out the solution!

Naomi [import]uid: 67217 topic_id: 18497 reply_id: 71224[/import]

cool

:slight_smile: [import]uid: 12482 topic_id: 18497 reply_id: 71226[/import]

Not to resurrect this thread, but I ended up getting my filters right and all my collisions are working correctly. I did have to make my kinematic objects all dynamic and I just set the gravity to 0.0 so it wouldn’t be a problem and added isSensor’s to the things I didn’t want collisions actually moving…

Now I have an interesting problem.

Just a quick setup. This is in effect a “skiing” game where there are things I pickup while moving left to right and there are things that block/kill the player.

So on the first time through, my player hits a blocking object (static physics body) and he bounces backwards and I detect the hit, kill the player and restart the level.

Now my player runs into the object a second time… he blows through it but triggers the collision and if there are other objects behind it, I get two hits.

Thoughts on that?
[import]uid: 19626 topic_id: 18497 reply_id: 71755[/import]