• Runtimes
  • Issue trying to fetch separate bounding boxes

  • تم التحرير
Related Discussions
...

I'm trying to retrieve two separate bounding boxes from 2 different skeletons to test collision between them. My issue is it seems the function 'spSkeleton_getAttachmentForSlotName' returns the same bounding box, no matter which skeleton was passed to it. Meaning, if I pass a player character's skeleton to the function to grab that skeleton's bounding box, and then I pass an ai character's skeleton to get it's bounding box, both bounding boxes retrieved from both skeleton's have the same address. So I can't test collision with them. Is this normal behavior or is there something else maybe wrong in my program? Code is below:

spAnimationState_apply(player->animationState, player->skeleton);
         spSkeleton_updateWorldTransform(player->skeleton);
         spAnimationState_apply(ai->animationState, ai->skeleton);
         spSkeleton_updateWorldTransform(ai->skeleton);

     spBoundingBoxAttachment* playerCollisionBox = (spBoundingBoxAttachment*)spSkeleton_getAttachmentForSlotName(player->skeleton, "collision-box", "test-box");
     spBoundingBoxAttachment* aiCollisionBox = (spBoundingBoxAttachment*)spSkeleton_getAttachmentForSlotName(ai->skeleton, "collision-box", "test-box");

    //playerCollsionBox == aiCollisionBox 

It is normal behavior: bounding boxes are attachments which are stateless and shared across skeleton instances. See graphic here:
Runtime Architecture - Spine Runtimes Guide: Class diagram

You can use BoundingBox computeWorldVertices to compute the world vertices for a particular skeleton. There is also SkeletonBounds, which is a convenience provided to make dealing with bounding boxes easier. It finds all the bounding boxes and computes the world vertices. You can use those directly (BoundingBox getPolygon) and do your own hit detection, or you can use the provided methods (eg BoundingBox aabbContainsPoint).