My current game is intended to involve some simple melee combat; to this end, when characters attack a CollisionSphere is attached to a particular joint (if present), and damage is dealt if it is detected to collide with another character’s personal collision geometry.
This presents a problem, however: since the joint in question is, in my main character’s case, at least, sufficiently close to the character’s collision geometry, collisions are detected between the character and its own attack geometry.
I have two solutions for this, I believe:
When the collision event is fired, compare the object impacted to the object that the attack is attached to. If they are the same, return without further action.
Set up bitmasks such that collision events are not fired for attacks and their owners.
Of those, bitmasks seem better to me: I imagine that this method would result in less calls, since the events wouldn’t be fired.
So, to this end I tried setting an “into” bitmask in each character, and then setting the inverse “from” bitmask in each attack object, using “invertInPlace”.
The resulting code looks something like this in the relevant sections:
class RevenantActor(GameObject): def __init__(self, -parameters here-): ... # "id" is currently just an integer, as I recall, # with the two current characters using the # values 1 and 2 self.id = id self.collider.setCollideMask(BitMask32(self.id)) ... def shoot(self): ... #"shot" is a tuple, the first value indicating # whether the shot was fired, and the # second containing the attack object itself, # if applicable. if shot: mask = BitMask32(self.id) #print mask mask.invertInPlace() #print mask shot.collider.node().setFromCollideMask(mask) ...
The problem is that, with invertInPlace, uh, “in place”, the game’s performance drops through the floor. With the other method given above, no such problem seems to be present.
This seems to be related to the currently-incomplete state of my enemy character, which would appear to result in multiple attack objects overlapping each other.
That seems fair enough at first, but according to a print statement, the numbers in question don’t seem to go above ten overlapping shots, and again, this doesn’t seem to be a problem when I’m comparing the shot’s owner to the impacted object. Similarly, if the objects are created with the same frequency, but made short-enough lived that they don’t overlap, the problem seems to disappear (or at least be significantly reduced).
Why is this? Is there a better method than invertInPlace?