Do you mean check if I collide, then reset the collision data and check again?
This code can make the camera to stop if the player go backward (down key):
#include "DarkGDK.h"
float angle1 = 0;
float angle2 = 0;
float keepkey = 0;
void control()
{
float x = dbObjectPositionX(1);
float y = dbObjectPositionY(1);
float z = dbObjectPositionZ(1);
float ocx = dbCameraPositionX();
float ocz = dbCameraPositionZ();
float ocy = dbCameraPositionY();
float ay = dbObjectAngleY(2);
if (dbUpKey() == 1)
{
dbMoveObject(1, 1.0);
}
if (dbDownKey() == 1)
{
dbMoveObject(1, -1.0);
}
// All buttons must be released in order to turn the cube agian.
if (keepkey == 0)
{
if (dbLeftKey() == 1)
{
dbYRotateObject(1, dbObjectAngleY(1) + 90);
angle1 = angle1 + 90;
keepkey = 1;
}
if (dbRightKey() == 1)
{
dbYRotateObject(1, dbObjectAngleY(1) - 90);
angle1 = angle1 - 90;
keepkey = 1;
}
}
// If no button is pressed, I turn the variable keepkey to 0.
if (dbScanCode() == 0)
{
keepkey = 0;
}
if (dbObjectCollision(1, 0) != 0)
{
dbPositionObject(1, x, y, z);
}
// I whant to turn the camera smooth, to aviod confusing.
if (angle1 < angle2)
{
angle2--;
}
else if (angle1 > angle2)
{
angle2++;
}
else
{
angle2 = angle1;
}
float cz = dbNewZValue(dbObjectPositionZ(1), dbWrapValue(angle2 + 180), 100);
float cx = dbNewXValue(dbObjectPositionX(1), dbWrapValue(angle2 + 180), 100);
dbPositionObject(2, cx, dbObjectPositionY(1) + 32, cz);
dbYRotateObject(2, angle2);
if (dbObjectCollision(2,0))
{
dbPositionObject(2,ocx,ocy,ocz);
dbYRotateObject(2, dbObjectAngleY(2));
dbPointObject(2, dbObjectPositionX(1), dbObjectPositionY(1), dbObjectPositionZ(1));
dbPointCamera(dbObjectPositionX(1), dbObjectPositionY(1), dbObjectPositionZ(1));
}
dbPositionCamera(dbObjectPositionX(2), dbObjectPositionY(2), dbObjectPositionZ(2));
dbYRotateCamera(dbObjectAngleY(2));
}
void DarkGDK ( void )
{
dbSyncOn();
// Player.
dbMakeObjectCube(1, 32);
dbPositionObject(1, 300, 16, 300);
// Camera Object.
dbMakeObjectCube(2, 100);
dbHideObject(2);
// Left Wall.
dbMakeObjectPlain(3, 500, 250);
dbPositionObject(3, 0, 125, 0);
// Right Wall.
dbMakeObjectPlain(4, 500, 250);
dbPositionObject(4, 0, 125, 500);
while ( LoopGDK ( ) )
{
control();
dbSync ( );
}
return;
}
But this code is better, but there is no backwardcheck:
if (dbObjectCollision(1, 0) != 0 && dbObjectCollision(1, 2) == 0)
{
dbPositionObject(1, x, y, z);
}