Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / my sample collision tutorial @@

Author
Message
kareem3d
15
Years of Service
User Offline
Joined: 3rd Aug 2009
Location:
Posted: 13th Aug 2009 23:50
HOW TO MAKE COLLISION WITH TWO SAMPLE BOXES ??

CAN ANYONE WRITE A SIMPLE TUTORIAL TO HELP ME......

OR HERE"S MY CODE ::
WHAT I NEED IS TO MAKE BOX(1) STOP WHEN IT HIT BOX(2)

#include "DarkGDK.h"
#include "SC_Collision.h"

void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );

SC_Start();

dbMakeCamera(1);
dbPositionCamera(1,0,0,-50);

dbMakeObjectBox(1,1,1,1);
dbPositionObject(1,0,0,0);
SC_SetupObject(1,0,0);

dbMakeObjectBox(2,6,3,1);
dbPositionObject(2,-10,0,0);
SC_SetupObject(2,0,0);

int speed=1;

//MAKING AN INTEGER FOR COLLISION
int collide=0;

while ( LoopGDK ( ) )
{
if(dbUpKey())
{
dbMoveObjectUp(1,speed);
//SHOULD I UPDATE THE BOX OR NOT??
SC_UpdateObject(1);
}
if(dbDownKey())
{
dbMoveObjectDown(1,speed);
SC_UpdateObject(1);
}
if(dbLeftKey())
{
dbMoveObjectLeft(1,speed);
SC_UpdateObject(1);
}
if(dbRightKey())
{
dbMoveObjectRight(1,speed);
SC_UpdateObject(1);
}

//WHAT I HAVE TO DO TO ELSE TO MAKE COLLISION ??
dbSync ( );
}
return;
}
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 14th Aug 2009 01:36
You have to check for the collision in your loop, i'd say at the end.
Just put this before you sync:

// check object 1 against 2
int isCollision = SC_objectCollision ( 1, 2 );

if ( isCollision == 1 ) // collision is happening, else 0 = no collision
{
... do stuff here ...
( move object back to old position for example... )
}

hope this helps a bit...
kareem3d
15
Years of Service
User Offline
Joined: 3rd Aug 2009
Location:
Posted: 14th Aug 2009 12:29 Edited at: 14th Aug 2009 12:42
thx alot man ,,

it will be great if u can be more specific in what should i write between the "if" brackets....
all i need is that object(1) don't penetrate object(2)
puppyofkosh
17
Years of Service
User Offline
Joined: 9th Jan 2007
Location:
Posted: 14th Aug 2009 17:01
He said try moving the object to its old position, so what you should do is...

Put this at the beginning of your loop



at the end of your loop put



then in the "if brackets"



You have to initialize some new variables, x, y, z, oldx, oldy, oldz, and I'm not sure if some of the commands are right (I didn't try it).
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 14th Aug 2009 17:44
Yes puppy of kosh, that's exactly what i meant!
Or you could just skip all of the moving if the two objects are colliding.

Your loop would then look something like this:

while ( LoopGDK ( ) )
{
int isCollision = SC_ObjectCollision ( 1, 2 );

if ( isCollision == 0 )
{

if(dbUpKey())
{ ... }
if(dbDownKey())
{ ... }
if(dbLeftKey())
{ ... }
if(dbRightKey())
{ ... }
}

// update screen
dbSync ( );
}

Hope this helps!
If not you may take a look at the Sparky Documentation or Samples... it's not that difficult.
good luck
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 14th Aug 2009 18:24
Ok, sorry - forget that!
( nonsense )
This will let you not be able to move your object anymore, after it has collided with the other object once!

you better stick to the previously posted method.
try to understand the basic principles of it...
kareem3d
15
Years of Service
User Offline
Joined: 3rd Aug 2009
Location:
Posted: 15th Aug 2009 11:36
that's exactly what i wanted,,, thx guys

i managed at last to make it work thanks to u....

Login to post a reply

Server time is: 2024-11-20 17:47:32
Your offset time is: 2024-11-20 17:47:32