Game Development Community

Collision Detection

by Shugar Ree · in General Game Discussion · 06/20/2003 (2:14 am) · 20 replies

1. I am trying to develop a simple pong game (my first game) and i cant figure out how to detect a collision between the ball and block. Do i need to create a border for each object?

2. My animations aren't transparent. I have set the transparency property in the movie script to the background color of the bmps.

Forgive me if these questions seem stupid, but i am new to game programming!

About the author

Recent Threads

  • Compiling New project

  • #1
    06/20/2003 (4:23 am)
    Have a look at the Borders & Collisions example

    you would need a border for the ball and the pong

    -Ron
    #2
    06/21/2003 (4:53 am)
    The Borders and collision example applies to 3D. I am thinking of a 2D object.
    #3
    06/21/2003 (7:03 am)
    You would then need to do something along the lines of pixel collision
    here is what I did (not efficient as it could be) for the invadors game I was going
    to-do for RE, but Chris stole *snicker*

    bool Invaders::CheckCollision (G2D_Image *Alien, G2D_Image *player)
    {
    	
        int left1, left2;
        int right1, right2;
        int top1, top2;
        int bottom1, bottom2;
    
        left1 = Alien->GetPosition().x;
        left2 = player->GetPosition().x;
    
        right1 = Alien->GetPosition().x + Alien->getWidth();
        right2 = player->GetPosition().x + player->getWidth();
    
        top1 = Alien->GetPosition().y;
        top2 = player->GetPosition().y;
    
        bottom1 = Alien->GetPosition().y + Alien->getHeight();
        bottom2 = player->GetPosition().y + player->getHeight();
    
        if (bottom1 < top2) return(0);
        if (top1 > bottom2) return(0);
    
        if (right1 < left2) return(0);
        if (left1 > right2) return(0);
    
        return(1);
    
    	
    }

    -Ron
    #4
    06/21/2003 (9:18 am)
    Odd, dang forum dbl posted for me *sigh*
    #5
    06/22/2003 (6:40 pm)
    For your pong game, you could use the border system. It can easily handle your game. However, you'll have to use the 3D vectors and just fix your borders to the plane. In your case the easiest might be to create borders where z = 0 and just ignore the z-component.

    You won't need to worry about any matrices in this case and you wont need to worry about any rotation stuff so the w (angular velocity) will remain zero.

    If you choose to use the border system, move the objects by changing their velocities, DON'T JUST REPOSITION THEM. This will override the collision system.

    As far as the transparency issue, make absolutely sure the RGB values you use in the movie script are the actual values in the backgrounds of the bitmaps. Sometimes these values are changed when you go from RGB to Index, etc.

    BTW these are not stupid questions. This is exactly what the Reaction Engine was designed to teach.

    Chris
    #6
    06/23/2003 (5:51 am)
    THANK YOU ALL!! Long Live RE (++chris && community)!!!
    #7
    06/23/2003 (8:02 am)
    No problem. Hope it helps!
    #8
    06/24/2003 (9:46 am)
    Help!!!! I am going CRAZY!!!!
    I am back with the same problem + some more.

    1. My new project compiles but i get the following errors when it comes to linking:
    Linking...
    Basic.obj : error LNK2001: unresolved external symbol "public: void __thiscall OS_Device::SetMenu(char const *)" (?SetMenu@OS_Device@@QAEXPBD@Z)
    Basic.obj : error LNK2001: unresolved external symbol "public: void __thiscall OS_Device::SetFullScreenMenuName(char const *)" (?SetFullScreenMenuName@OS_Device@@QAEXPBD@Z)
    Basic.obj : error LNK2001: unresolved external symbol "public: void __thiscall OS_Device::SetWindowMenuName(char const *)" (?SetWindowMenuName@OS_Device@@QAEXPBD@Z)
    Basic.obj : error LNK2001: unresolved external symbol "public: void __thiscall OS_Device::SetWindowName(char const *)" (?SetWindowName@OS_Device@@QAEXPBD@Z)
    Basic.obj : error LNK2001: unresolved external symbol "public: void __thiscall OS_Device::SetAppName(char const *)" (?SetAppName@OS_Device@@QAEXPBD@Z)
    Basic.obj : error LNK2001: unresolved external symbol "public: int __thiscall RE_IO::IO_INI::GetString(char const *,char const *,char const *,char *,int,char const *)" (?GetString@IO_INI@RE_IO@@QAEHPBD00PADH0@Z)
    Basic.obj : error LNK2001: unresolved external symbol "class RE_IO::IO_INI * RE_IO::Device_Ini" (?Device_Ini@RE_IO@@3PAVIO_INI@1@A)
    Basic.obj : error LNK2001: unresolved external symbol "public: void __thiscall OS_Device::SetFrameRate(double)" (?SetFrameRate@OS_Device@@QAEXN@Z)
    Basic.obj : error LNK2001: unresolved external symbol "public: long __thiscall RE_GFX::GFX_Device::InitGFXMode(void)" (?InitGFXMode@GFX_Device@RE_GFX@@QAEJXZ)
    Basic.obj : error LNK2001: unresolved external symbol "public: int __thiscall RE_GFX::GFX_Device::Insert(class RE_GFX::GFX_Render_Object *)" (?Insert@GFX_Device@RE_GFX@@QAEHPAVGFX_Render_Object@2@@Z)
    Basic.obj : error LNK2001: unresolved external symbol "public: __thiscall RE_GFX::G2D_Text::G2D_Text(void)" (??0G2D_Text@RE_GFX@@QAE@XZ)
    Basic.obj : error LNK2001: unresolved external symbol "public: int __thiscall RE_TXT::FONT_Device::Register(char const *,char const *,int,int,bool,bool,bool)" (?Register@FONT_Device@RE_TXT@@QAEHPBD0HH_N11@Z)
    Basic.obj : error LNK2001: unresolved external symbol "public: bool __thiscall RE_INPUT::Mouse_Device::Create(void)" (?Create@Mouse_Device@RE_INPUT@@QAE_NXZ)
    Basic.obj : error LNK2001: unresolved external symbol "public: bool __thiscall RE_GFX::GFX_Device::Create(enum RE_GFX::DIM,bool)" (?Create@GFX_Device@RE_GFX@@QAE_NW4DIM@2@_N@Z)
    Basic.obj : error LNK2001: unresolved external symbol "class RE_INPUT::Mouse_Device * RE_INPUT::Device_Mouse" (?Device_Mouse@RE_INPUT@@3PAVMouse_Device@1@A)
    Basic.obj : error LNK2001: unresolved external symbol "class RE_TXT::FONT_Device * RE_TXT::Device_Font" (?Device_Font@RE_TXT@@3PAVFONT_Device@1@A)
    Basic.obj : error LNK2001: unresolved external symbol "public: __thiscall RE_TXT::FONT_Device::FONT_Device(void)" (??0FONT_Device@RE_TXT@@QAE@XZ)
    Basic.obj : error LNK2001: unresolved external symbol "public: bool __thiscall RE_GFX::GFX_Device::Render(void)" (?Render@GFX_Device@RE_GFX@@QAE_NXZ)
    Basic.obj : error LNK2001: unresolved external symbol "public: void __thiscall RE_GFX::GFX_Device::Update(double)" (?Update@GFX_Device@RE_GFX@@QAEXN@Z)
    Basic.obj : error LNK2001: unresolved external symbol "public: void __thiscall RE_INPUT::Mouse_Device::SetCursorFromFile(char const *)" (?SetCursorFromFile@Mouse_Device@RE_INPUT@@QAEXPBD@Z)
    Basic.obj : error LNK2001: unresolved external symbol "public: void __thiscall RE_INPUT::Mouse_Device::Update(void)" (?Update@Mouse_Device@RE_INPUT@@QAEXXZ)
    external symbol _WinMain@16
    Debug/Basic.exe : fatal error LNK1120: 39 unresolved externals
    Error executing link.exe.

    Basic is the project name - im trying to get the basic framework first.

    I have included all the required paths -
    \Include, \Include\D3D\, \Lib
    #9
    06/24/2003 (9:51 am)
    Make sure your path is Libs not Lib. And make sure the Reaction Engine (debug).lib is in that directory.
    #10
    06/24/2003 (9:59 am)
    I tried what you said about the previous problem it didn,t work. Because my project wasn't working i modified the code in the "Getting_started" example.

    In the Borders and Collision exmple how did you compute the coordinates you passed to BORDER_STRUCT_LINETO(Vec(11.5, 0, 11)) ??
    #11
    06/24/2003 (10:08 am)
    Did you get it to link? I guess I don't quite understand your last post?

    As for the borders, I used the values in 3D max. In your case, you probably have bitmaps with a width and height. These should work for your values.

    BTW You won't be able to display your borders like I did in the Border & Collision example since you're using 2D. But the collision code should all still work exactly the same way.

    Does this help?
    #12
    06/24/2003 (12:29 pm)
    It still doesn't link!! The examples work properly. But when it comes to creating a new project in a new workspace, it does't link.

    So at the moment i am modifying the getting_started example to try out my ideas. So Frustrating.......

    Anyway i have managed to move the ball but it doesn't bounce of the walls or the block. This is how i created the border:-

    BallBorder->OpenBorder();
    BallBorder->Insert(new BORDER_STRUCT_LINETO(Vec3(37,0,0), &prop));
    BallBorder->Insert(new BORDER_STRUCT_LINETO(Vec3(37,37,0), &prop));
    BallBorder->Insert(new BORDER_STRUCT_LINETO(Vec3(0,37,0), &prop));
    BallBorder->Insert(new BORDER_STRUCT_LINETO(Vec3(0,0,0), &prop));
    BallBorder->CloseBorder();
    BallBorder->SetCollisionQueue(new RES_PQ("Col_Q", true, 5, 3, 0));
    BallBorder->Update(Vec3(0), Vec3(0));
    BallBorder->SetShowObject(true);
    BallBorder->SetShowBorder(GFX_SHOW_BORDER);
    Device_GFX->Insert(BallBorder);

    NB: the image is 37 X 37.
    Collision detection code is the same as the Borders_n_Collision example. angular velocity = 0
    #13
    06/25/2003 (12:28 pm)
    As far as your link errors, it looks like you are definitely NOT linking the library in correctly. Those unresolved externals are all RE SDK calls. Double check the library paths.

    I believe your border structs are backward. They currently go clockwise, they should go counterclockwise. Just switch the order of the borders like this

    BallBorder->Insert(new BORDER_STRUCT_LINETO(Vec3(37,0,0), &prop));
    BallBorder->Insert(new BORDER_STRUCT_LINETO(Vec3(0,0,0), &prop));
    BallBorder->Insert(new BORDER_STRUCT_LINETO(Vec3(0,37,0), &prop));
    BallBorder->Insert(new BORDER_STRUCT_LINETO(Vec3(37,37,0), &prop));

    BTW In the way you're using the borders they won't be visible. So setting the SetShowObject to true is unnecessary, as is the SetShowBorder.

    Hope this helps.

    Chris
    #14
    06/27/2003 (3:32 am)
    Collision detection still doesn't work.
    I am taking a break from RE!!!!
    #15
    06/27/2003 (3:58 am)
    When I wrote version 1 of invaders I used all 2D and the function posted above and all worked accordingly.

    I was unable to get Borders & Collisions to work with my 2D objects either. I decided to K.I.S.S (Keep It Simple Stupid) it and forgo the 3D stuff for a 2D game

    -Ron
    #16
    06/27/2003 (5:49 am)
    I'll try to use your method you described above and keep it simple for now. As you said simple and stupid and hopefully i'll get some result...makes a big diffrence!!

    Thanks Ron.
    #17
    06/28/2003 (2:04 am)
    Sorted out the unrsolved external errors...phew!!!

    Ron your method above worked fine. However, the ball kept bouncing off the block a few pixels before actual collision...

    Thanks once again.
    #18
    06/30/2003 (6:40 am)
    Shugar..did you do the using namespace XXX....????
    #19
    07/01/2003 (4:09 am)
    For what in particular???
    #20
    07/02/2003 (1:12 pm)
    Shugar,

    You're not the first to have difficulties getting the Borders and Collisions working in 2D. I'll try to add a 2D collision layer, to simplify this for games that only use 2D. That said, I'm totally swamped so don't expect it right away ;)

    Chris