Collisions detection for manually moved objects?

edited March 2011 in Help request
For the next part of my project, I'm turning now to implementing some sort of collision system.

At first I looked at the physics system, but if I add dynamic bodies to my objects, one will push the other, and I need objects to pass by each other.

If I make both objects static, then according to the wiki, there will be no collision detection.

I guess what I really need is some kind of home made overlap detection system as opposed to a physics collision detection.

So then I thought I can calculate this by testing the positions and widths of the two objects during a custom event to test if they overlap. What I noticed though is that when I do an orxObject_GetSize() during a custom event, I get the same value each time, even though the size of my animation frames are not always the same.

(is this because it always stays the initial value of the first frame no matter what happens afterwards?)

So this will make my overlap detection very inaccurate.

Is there any advice as to how I can go about implementing something like this?

Comments

  • edited March 2011
    sausage wrote:
    For the next part of my project, I'm turning now to implementing some sort of collision system.

    At first I looked at the physics system, but if I add dynamic bodies to my objects, one will push the other, and I need objects to pass by each other.

    Well, yes and no. By default body parts are solid, which means they'll interact with each other and trigger reactions. If you set the config property Solid to false on a part, it'll give you the collision info (through events) but won't trigger any physics reaction. They act as sensors.
    If I make both objects static, then according to the wiki, there will be no collision detection.

    That's right, you still need to use dynamic bodies.
    I guess what I really need is some kind of home made overlap detection system as opposed to a physics collision detection.

    So then I thought I can calculate this by testing the positions and widths of the two objects during a custom event to test if they overlap. What I noticed though is that when I do an orxObject_GetSize() during a custom event, I get the same value each time, even though the size of my animation frames are not always the same.

    (is this because it always stays the initial value of the first frame no matter what happens afterwards?)

    So this will make my overlap detection very inaccurate.

    Is there any advice as to how I can go about implementing something like this?

    Yes, that would be a better solution in your case as your character's size varies a lot and there's still no skeletal animation support in orx (which would allow to have separate objects for limbs, for example, that would allow bodies to track their movement).

    As you noted, orxObject_GetSize() gives you the size of the orxGRAPHIC directly linked to the object. If you want to get the size of the current animation's graphic, you simply need to get it first and query its size afterward. Here's how to do it:
    orxANIMPOINTER *pstAnimPointer;
    orxVECTOR vSize;
    
    pstAnimPointer = orxOBJECT_GET_STRUCTURE(MyObject, ANIMPOINTER);
    if(pstAnimPointer != orxNULL)
    {
      orxGRAPHIC *pstGraphic;
    
      pstGraphic = orxGRAPHIC(orxAnimPointer_GetCurrentAnimData(pstAnimPointer));
    
      if(pstGraphic != orxNULL)
      {
        orxGraphic_GetSize(pstGraphic, &vSize);
      }
    }
    
  • edited March 2011
    iarwain wrote:
    If you set the config property Solid to false on a part, it'll give you the collision info (through events) but won't trigger any physics reaction. They act as sensors.

    Works beautifully! Such a simple solution. Ok I can probably use this. It doesn't have to be skeletal. A simple box will work fine.
    orxGraphic_GetSize(pstGraphic, &vSize);
    

    Of course! I'm working with varying graphics sizes not object sizes. Can't believe I didn't think of this.

    Thanks again for both of these. Either will do me fine.
Sign In or Register to comment.