Object GroupID and BoxPick

edited April 2014 in Help request
Hey, I'm working on getting a demo of our game ready to present, and I'm having a few issues with letting the character interact with buttons. The implementation is that each object has an associated "Activated" method, which defines how the object responds by being interacted with.

When the player presses the key, I get the bounding box for the character and attempt to do a boxpick on the region. Now, naturally, it's just going to return the player, so I set the GroupID of the button and suddenly the button stops rendering. I then tried setting the GroupID of the player and he keeps rendering, but the boxpick still returns his object.

Is there a way to get all objects found through box pick or is there a better way to do this?


  • edited April 2014
    Hi softero!

    By changing the group of an object, you not only affect its picking but also its rendering.
    A good analogy would be layers in some other engines.

    If you want to completely separate your "interactive" objects from the rest, then you can use the group property for objects.
    You'll also have to modify your camera to let it know to render not only the "default" group of objects but also the "interactive" one.
    Please note that, similar to layers, groups will be rendered in different passes, ie. you won't be able to have a "interactive" object in the back, then a "default" one and finally a "interactive" one on top of them both: there's no mixing of groups during rendering, no matter what the Z value of the objects is.

    More details here.

    To sum it up, if you want group separation, you can use this kind of setup:
    Group = interactive
    ; No group means it is in the "default" group
    GroupList = interactive # default; First render the "interactive" group, then the "default" one

    If you can't make such a clean separation of object groups in your game, you can pick what's behind your player by modifying the Z range of your box: make sure to exclude the player from the picking box.

    Let's say your player has a Z = 0.5 and your interactive objects are all between Z=0.7 and Z=1.0 -> MyBox.vTL.fZ = 0.7 / MyBox.vBR.fZ = 1.0 will only select your interactive objects during the picking.
  • edited April 2014
    Excellent, thank you. That helps a bunch. I didn't realize that it affected rendering. We'll have to mess with that a lot. If I wanted to have interactive objects in both the foreground and background, I suppose I would have to implement two groups for "foregroundInteract" and "backgroundInteract" and then run two different BoxPicks for each group?
  • edited April 2014
    Yes, exactly.

    What I usually do is to keep a config property that holds the list of pickable groups and iterate over it. This way I can easily change which groups to consider for picking at runtime.

    Something like:

    PickList = ForegroundPick # BackgroundPick

    orxVECTOR vPos; // + assign picking position
    orxOBJECT *pstPickObject = orxNULL;
    for(orxS32 i = 0;
        (i < orxConfig_GetListCounter("PickList")) && (pstPickObject == orxNULL);
      // Picks object
      pstPickObject = orxObject_Pick(&vPos, orxString_GetID(orxConfig_GetListString("PickList", i)));

    For some reason, if I only want to pick objects in the background at some point, all I have to do is update the content of MyGame.PickList and remove the ForegroundPick group from it, either in code or using commands/timelines.
Sign In or Register to comment.