Best use of collision rules?
Posted: Sat Nov 12, 2011 11:36 pm
Hey Norbo, I'm building a graphically 2d action rpg using BEPU. It's working out great -- making things like jumping and projectiles really fun to set up. I'm getting to the point where I have to decide on how I'm dealing with collision rules for my simulation, and I thought I'd ask your advice.
I'm using a modified version of the SimpleCharacterController for heroes and some enemies, while other enemies just get a simple rotation-locked sphere or box. I've also got lots of trigger areas, which can be either cylinders or boxes, which are meant to collide with nothing but the thing that triggers them. I'm using attack hitboxes in a similar way, and I've also got item drops, which collide with walls and the floor, but nothing else (found it annoying to have them collide with heroes/enemies).
Up until now I've mostly relied on collision groups, and not used the personal or specific collision rules much. However, when I started using the SimpleCharacterController, I ran into a problem -- the raycast on it, not being part of a collision group, collides with everything... even trigger areas, attack hitboxes, and other things never meant to do anything but raise events.
I understand I can use the overload of the broadphaseentry.raycast to provide a filter. However, the problem got me thinking more about how I've been using the collision rules, and only relying on the collision groups, which doesn't seem like the best use of the engine.
I came up with a new solution: create a few specific collision rule dictionaries named things like "OnlyHero" and "OnlyEnemy", and just have each creature, as it's being created, add itself to this universal specifc dictionary. Then, trigger areas can simply reference whatever specific dictionary is appropriate for them, and then have their personal rule set to CollisionRule.NoBroadPhase.
My question is a pretty general one: are these equally valid approaches? Is there an obvious better way to approach the complexity of all these interlocking collision rules?
Also, lets say I create a specific dictionary called "OnlyWalls". Every wall, when the level is loaded, is going to add itself to this group. This is going to lead to a really massive dictionary. If I have a bunch of objects all using this OnlyWalls specific dictionary, is that going to take a lot more effort to look up each wall piece than just a simple collision group? Should I avoid making specific dictionaries with thousands of entries?
Another idea is to change the CollisionRuleCalculator to look at collision groups before personal rules. That way, things could still obey collision group rules, but also have a default personal rule of NoBroadPhase, if no collision group relationship exists (as in the case of the character controller's raycast.)
Sorry about the length. Thanks for reading, Norbo.
Alex
*edit* I guess another approach would be to set up a collision rule instance for each type of game object (hero, enemy, trigger area, etc..), define the relationships between them, and then set every individual game object, on initialization, to reference those collision rules. That way there wouldn't be as many entries in the specific dictionary, but I haven't quite worked out how things would work with all enemies sharing the same collision rules... hmm
I'm using a modified version of the SimpleCharacterController for heroes and some enemies, while other enemies just get a simple rotation-locked sphere or box. I've also got lots of trigger areas, which can be either cylinders or boxes, which are meant to collide with nothing but the thing that triggers them. I'm using attack hitboxes in a similar way, and I've also got item drops, which collide with walls and the floor, but nothing else (found it annoying to have them collide with heroes/enemies).
Up until now I've mostly relied on collision groups, and not used the personal or specific collision rules much. However, when I started using the SimpleCharacterController, I ran into a problem -- the raycast on it, not being part of a collision group, collides with everything... even trigger areas, attack hitboxes, and other things never meant to do anything but raise events.
I understand I can use the overload of the broadphaseentry.raycast to provide a filter. However, the problem got me thinking more about how I've been using the collision rules, and only relying on the collision groups, which doesn't seem like the best use of the engine.
I came up with a new solution: create a few specific collision rule dictionaries named things like "OnlyHero" and "OnlyEnemy", and just have each creature, as it's being created, add itself to this universal specifc dictionary. Then, trigger areas can simply reference whatever specific dictionary is appropriate for them, and then have their personal rule set to CollisionRule.NoBroadPhase.
My question is a pretty general one: are these equally valid approaches? Is there an obvious better way to approach the complexity of all these interlocking collision rules?
Also, lets say I create a specific dictionary called "OnlyWalls". Every wall, when the level is loaded, is going to add itself to this group. This is going to lead to a really massive dictionary. If I have a bunch of objects all using this OnlyWalls specific dictionary, is that going to take a lot more effort to look up each wall piece than just a simple collision group? Should I avoid making specific dictionaries with thousands of entries?
Another idea is to change the CollisionRuleCalculator to look at collision groups before personal rules. That way, things could still obey collision group rules, but also have a default personal rule of NoBroadPhase, if no collision group relationship exists (as in the case of the character controller's raycast.)
Sorry about the length. Thanks for reading, Norbo.
Alex
*edit* I guess another approach would be to set up a collision rule instance for each type of game object (hero, enemy, trigger area, etc..), define the relationships between them, and then set every individual game object, on initialization, to reference those collision rules. That way there wouldn't be as many entries in the specific dictionary, but I haven't quite worked out how things would work with all enemies sharing the same collision rules... hmm