Results 1 to 4 of 4

Thread: collision detection problems!

                  
   
  1. #1
    DCEmu Regular psiko_scweek's Avatar
    Join Date
    Apr 2006
    Posts
    315
    Rep Power
    71

    Default collision detection problems!

    Hey!! whats wrong with my collision detection code? It works great, cept it registers the collision one pixel too many! so, basically it registers one pixel outside of my image.

    Code:
    nt obj_IsCollision(Object *object1, Object *object2)
    {
    int obj_top1, obj_top2;
    int obj_bot1, obj_bot2;
    int obj_rigt1, obj_rigt2;
    int obj_left1, obj_left2;
    
    obj_left1 = object1->getX();
    obj_left2 = object2->getX();
    
    obj_top1 = object1->getY();
    obj_top2 = object2->getY();
    
    obj_rigt1 = object1->getX() + object1->getGraphicWidth();
    obj_rigt2 = object2->getX() + object2->getGraphicWidth();
    
    obj_bot1 = object1->getY() + object1->getGraphicHeight();
    obj_bot2 = object2->getY() + object2->getGraphicHeight();
    
    if (obj_bot1 < obj_top2) return(0);
    if (obj_top1 > obj_bot2) return(0);
    
    if (obj_rigt1 < obj_left2) return(0);
    if (obj_left1 > obj_rigt2) return(0);
    
    return 1;

  2. #2
    GP2X Coder/Moderator
    Join Date
    Jan 2006
    Posts
    1,678
    Rep Power
    87

    Default

    int obj_IsCollision(Object *object1, Object *object2)
    {
    int obj_top1, obj_top2;
    int obj_bot1, obj_bot2;
    int obj_rigt1, obj_rigt2;
    int obj_left1, obj_left2;

    obj_left1 = object1->getX();

    obj_left2 = object2->getX();

    obj_top1 = object1->getY();

    obj_top2 = object2->getY();

    obj_rigt1 = object1->getX() + object1->getGraphicWidth();

    obj_rigt2 = object2->getX() + object2->getGraphicWidth();

    obj_bot1 = object1->getY() + object1->getGraphicHeight();

    obj_bot2 = object2->getY() + object2->getGraphicHeight();

    if (obj_bot1 <= obj_top2) return(0);

    if (obj_top1 >= obj_bot2) return(0);
    if (obj_rigt1 <= obj_left2) return(0);

    if (obj_left1 >= obj_rigt2) return(0);

    return 1;
    }
    .

  3. #3
    DCEmu Regular psiko_scweek's Avatar
    Join Date
    Apr 2006
    Posts
    315
    Rep Power
    71

    Default yeah

    lol yeah thats what I have!, i dont know what happened to the code when I copied it, thanks for fixing it.

    psiko

  4. #4
    DCEmu Regular psiko_scweek's Avatar
    Join Date
    Apr 2006
    Posts
    315
    Rep Power
    71

    Default

    wow, im retarded, i didnt even see you fixed my problem in that post as well as the issue with my copying.

    thanks!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •