SelfFlags & CheckMask

edited October 2013 in General discussions
Been wanting to understand collision masking for sometime and I can put it off no longer.

I've read and read and read through the API, Wiki & this topic https://forum.orx-project.org/discussion/6340#Comment_6341 to full grasp how it works.

Is my understand correct as follows:

* Box 2D only allows 16 different "categories"
* You need to set up a flag for one object, and a checkmask for the other, and do the same in reverse of those two objects in order to have a collision.

So if I think in terms of binary, 0xFFFF is 65535 which is:

1111111111111111

Which is 16 binary digits, each representing a category.

So now I can define self flags & check masks to my objects like so:
[HeroBodyPart]
SelfFlags = 0000000000000001 ;should be hex, but to illustrate the point....
CheckMask = 0000000000000110
(checkmask essentially WallA/B & Enemy)

[WallA_BodyPart]
SelfFlags = 0000000000000010
CheckMask = 0000000000000101
(checkmask essentially Hero & Enemy)

[WallB_BodyPart]
SelfFlags = 0000000000000010
CheckMask = 0000000000000101
(checkmask essentially Hero & Enemy)

[EnemyBodyPart]
SelfFlags = 0000000000000100
CheckMask = 0000000000000011
(checkmask essentially WallA/B & Enemy)


So in the above, hero matches with wallA/B (also with enemy), but wall must also match with hero to create an actual collision.

I think that's the theory.. am I right?

I'll try it out and post back. Hopefully this might help with others who find this a little tricky.

Comments

  • edited October 2013
    Now see, the lesson here kids, is that it doesn't matter how long you fiddle around with selfflags & checkmasks, switching things around and doing fancy math...

    if you put the config on body sections rather than bodypart sections, you're not going to get anywhere.

    I've edited the above to illustrate that the configs go into bodypart sections. :( :)
  • jimjim
    edited October 2013
    Do you know that, you can define literal value of SelfFlags and CheckMasks, like this and no need to define them in hex anymore.
    https://forum.orx-project.org/discussion/6571#Comment_6575
  • edited October 2013
    This is the final ini (the parts only, which is what matters) of that post.
    
    [Physics]
    Gravity         = (0, 981, 0)
    DimensionRatio  = 0.01
    CollisionFlagList = arrow # ground # character # monster
    
    [FullGroundPart]
    Type        = box
    Restitution = 0.0
    Friction    = 1.0
    SelfFlags   = ground
    CheckMask   = arrow # ground # character # monster
    Solid       = true
    Density     = 1.0
    
    [ArrowBodyHead]
    Type        = mesh
    VertexList  = (6, 2, 0) # (6, -4, 0) # (12, -1, 0)
    Restitution = 0.0
    Friction    = 1.0
    SelfFlags   = arrow
    CheckMask   = ground # monster
    Solid       = true
    
    [ArrowBodyTail]
    Type        = mesh
    VertexList  = (6, 0, 0) # (-12, 0, 0) # (-12, -2, 0) # (6, -2, 0)
    Restitution = 0.0
    Friction    = 1.0
    SelfFlags   = arrow
    CheckMask   = ground # monster
    Solid       = true
    
    [MainCharBodyPart]
    Type        = box
    Restitution = 0.0
    Friction    = 0.0
    SelfFlags   = character
    CheckMask   = ground # monster
    Solid       = true
    
    [Monster_Normal_BodyPart]
    Type        = box
    Restitution = 0.0
    Friction    = 0.0
    SelfFlags   = monster
    CheckMask   = arrow # ground # character
    Solid       = true
    Density     = 1.0
    

    Also, if you need to change the flags in game (as I needed, since after an arrow hit a monster or the ground it should no longer hit monsters):
    orxBODY* arrowBody = orxOBJECT_GET_STRUCTURE(currentWatcher->arrow, BODY);
    orxBODY_PART* arrowBodyPart = orxBody_GetNextPart(arrowBody, orxNULL);
    while(arrowBodyPart != orxNULL){
      orxBody_SetPartCheckMask(arrowBodyPart, orxPhysics_GetCollisionFlagValue("ground"));
      arrowBodyPart = orxBody_GetNextPart(arrowBody, arrowBodyPart);
    }
    
  • edited October 2013
    jim wrote:
    Do you know that, you can define literal value of SelfFlags and CheckMasks, like this and no need to define them in hex anymore.
    https://forum.orx-project.org/discussion/6571#Comment_6575

    Yep I noticed this discussed in Knolan's thread and I did try literals but they didn't work for me... I think maybe these are a orx 1.4 feature. I've been trying to get away with not admitting I haven't upgraded my project yet :)

    Will do soon.. I'm just on too much of a roll.

    Thanks for the full example there, Knolan, that's great.
  • edited October 2013
    Well, everything has been said here. I'm away from the forum for one day and that's when everybody else is active! ;)

    As a side note, if you really want it you can use binary representation for any config numbers (including flags&masks) using the prefix 0b:
    [HeroBodyPart] 
    SelfFlags = 0b0000000000000001
    CheckMask = 0b0000000000000110
    
  • edited October 2013
    Ah thanks, yes I think I'd prefer to use binary. I'll use this format now.
Sign In or Register to comment.