Box2D Forums

It is currently Sat May 25, 2013 1:59 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Wed Apr 18, 2012 11:06 am 
Offline

Joined: Mon Apr 09, 2012 7:26 am
Posts: 7
Hello! :) I'm having an issue with collision filtering. I'm using Citrus Engine 2, which uses Box2D for its physics. CE has a custom class that lets you reference bits used in collision filtering by strings, and I've attached that class as a file for reference. (CE is open source, btw.)

I've been reading over the CE manual, Box2D manual, and picking apart tutorials and such, and I think I have this set up properly, but I still have an issue. I have four main objects in my game:

  • Obstacles (walls) - assigned to the "Level" collision category
  • The player - assigned to "GoodGuys"
  • Zombies - assigned to "BadGuys"
  • Bullets - assigned to "Bullets"

The Bullets are set to collide with everything but the player, yet they are also not colliding with the Obstacles. I need for that to happen so I can have ricochet effects and such. The Player and zombies have no problems colliding with the walls.

In my initialize() function in my GameState class, when the game first runs, I have this:
Code:
CollisionCategories.Add("Bullets");


Level, GoodGuys, and BadGuys are already added to Citrus Engine by default.

In my Player class, I have this:
Code:
override protected function defineFixture():void
{
   super.defineFixture();
   _fixtureDef.filter.categoryBits = CollisionCategories.Get("GoodGuys");
   _fixtureDef.filter.maskBits = CollisionCategories.GetAllExcept("Bullets");
}//


Zombie class:
Code:
override protected function defineFixture():void
{
   super.defineFixture();
   _fixtureDef.filter.categoryBits = CollisionCategories.Get("BadGuys");
   _fixtureDef.filter.maskBits = CollisionCategories.GetAll();
}//


Obstacle class:
Code:
override protected function defineFixture():void
{
   _fixtureDef = new b2FixtureDef();
   _fixtureDef.shape = _shape;
   _fixtureDef.density = 1;
   _fixtureDef.friction = 0;
   _fixtureDef.restitution = 1;
   _fixtureDef.filter.categoryBits = CollisionCategories.Get("Level");
   _fixtureDef.filter.maskBits = CollisionCategories.GetAll();
}//


Bullet class:
Code:
override protected function defineFixture():void
{
   super.defineFixture();
   _fixtureDef.filter.categoryBits = CollisionCategories.Get("Bullets");
   _fixtureDef.filter.maskBits = CollisionCategories.GetAllExcept("GoodGuys");
}//


If I'm understanding all of the forum posts and such that I've read, this is the way to do things. I'm betting that I'm not understanding it properly, so any suggestions on what I'm doing wrong would be greatly appreciated!

EDIT: Never mind, I fixed it. Turns out my filtering is correct, but I was using the PhysicsObject class for my walls in the level instead of the Obstacles class. Oops.


Attachments:
File comment: Collision Categories class
CollisionCategories.txt [3.87 KiB]
Downloaded 77 times
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Exabot [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group