Another thread another problem.
From yesterday I can not use properly the function SC_GetCollisionSlideX (SC_GetCollisionSlideY and SC_GetCollisionSlideZ). The program freezes when it should go to place the object that collided.
The problem resides in the fact that SC_GetCollisionSlideX (SC_GetCollisionSlideY and SC_GetCollisionSlideZ) return a value of 1.#QNAN00. In the last day it worked, but since yesterday no longer works, and I do not seem to have changed anything. Is also very strange that if I use one object the function works, if I use two or more objects there is the problem. Moreover, if I use in the setup as the type of collision Collision box (2) two objects of the same type do not create problems, while 3 and more yes. When used as a kind of collision the Sphere collision (1) the problem is not created with an object, but with two or more objects.
In the image you can see that SC_SphereSlide return 1 (the terrain) but SC_GetCollisionSlideX return 1.#QNAN00.
Here some code.
Setup of objects
SC_SetupObject( i+firstEnemies, groupEnemy, 1 );
The function that move enemies (objects that collide with ground and which create the problem.
void moveEnemies(void) {
for( int i = firstEnemies; i < firstEnemies+numEnemies; i++ ) {
if(dbObjectExist(i)==1) {
if(mobs[i-firstEnemies].timerSoundEnemy==0) {
dbPlaySound(soundEnemy);
mobs[i-firstEnemies].timerSoundEnemy=1000;
}
else {
mobs[i-firstEnemies].timerSoundEnemy--;
}
float oldx = dbObjectPositionX(i);
float oldy = dbObjectPositionY(i);
float oldz = dbObjectPositionZ(i);
char positionCObjX[40];
char positionCObjY[40];
char positionCObjZ[40];
if(distanceBetween2Points(dbObjectPositionX(i),dbObjectPositionY(i),dbObjectPositionZ(i),dbObjectPositionX(character),dbObjectPositionY(character),dbObjectPositionZ(character))<=maxDistance) {
mobs[i-firstEnemies].mode=2; //insegue
if(distanceBetween2Points(dbObjectPositionX(i),dbObjectPositionY(i),dbObjectPositionZ(i),dbObjectPositionX(character),dbObjectPositionY(character),dbObjectPositionZ(character))<=maxAttack) {
mobs[i-firstEnemies].mode=3; //attacca
}
}
else {
if(mobs[i-firstEnemies].timeIdle==0) {
mobs[i-firstEnemies].mode=1; //vai in mode normal e comincia a muoverti
mobs[i-firstEnemies].timeIdle=300;
}
else {
if(mobs[i-firstEnemies].timeMove==0) {
mobs[i-firstEnemies].mode=0; //stai in idle mode, cioè fermo sul posto
}
}
}
if(mobs[i-firstEnemies].health<=20) {
mobs[i-firstEnemies].mode=4; //mode 4 significa che la vita del mob è minore di 20 e quindi fugge
dbYRotateObject(mobs[i-firstEnemies].id,dbObjectAngleY(character)); //fugge nella direzione opposto al player
mobs[i-firstEnemies].recoveryHealth=true;
}
if(mobs[i-firstEnemies].timerHealth==0 && mobs[i-firstEnemies].health<=50 && mobs[i-firstEnemies].recoveryHealth==true ) {
mobs[i-firstEnemies].health++;
if(mobs[i-firstEnemies].health<=20) {
mobs[i-firstEnemies].timerHealth=150;
}
else {
mobs[i-firstEnemies].timerHealth=300;
}
}
else if(mobs[i-firstEnemies].timerHealth>0) {
mobs[i-firstEnemies].timerHealth--;
}
else if(mobs[i-firstEnemies].health>50) {
mobs[i-firstEnemies].recoveryHealth=false;
}
if (dbObjectPositionX(mobs[i-firstEnemies].id)<0) {
//srand(dbTimer());
dbYRotateObject(i,180);
}
if (dbObjectPositionZ(mobs[i-firstEnemies].id)<0) {
//srand(dbTimer());
dbYRotateObject(i,180);
}
if (dbObjectPositionX(mobs[i-firstEnemies].id)>(int)dbObjectSizeX(terrain)) {
//srand(dbTimer());
dbYRotateObject(i,180);
}
if (dbObjectPositionZ(mobs[i-firstEnemies].id)>(int)dbObjectSizeZ(terrain)) {
//srand(dbTimer());
dbYRotateObject(i,180);
}
switch(mobs[i-firstEnemies].mode) {
case 0:
dbMoveObject(i,0);
//sta fermo
break;
case 1:
if(mobs[i-firstEnemies].timeMove==0) {
srand(dbTimer());
dbYRotateObject(i,dbWrapValue(dbObjectAngleY(i) + rand()%360));
mobs[i-firstEnemies].timeMove=800;
}
dbMoveObject(i,mobs[i-firstEnemies].velocityEnemies);
//lancia particelle laser a 360° e si muove
if(mobs[i-firstEnemies].speedFireParticle==0) {
dbPositionSound(soundFireParticleEnemey,dbObjectPositionX(mobs[i-firstEnemies].id),dbObjectPositionY(mobs[i-firstEnemies].id),dbObjectPositionZ(mobs[i-firstEnemies].id));
dbPlaySound(soundFireParticleEnemey);
mobsAttack(mobs[i-firstEnemies].id,1);
mobs[i-firstEnemies].speedFireParticle=speedFireEnemy;
}
else {
mobs[i-firstEnemies].speedFireParticle--;
}
break;
case 2:
dbPointObject(i, dbObjectPositionX(character), dbObjectPositionY(character), dbObjectPositionZ(character) );
dbMoveObject(i,mobs[i-firstEnemies].velocityEnemies );
//insegue senza attaccare
break;
case 3:
dbPointObject(i, dbObjectPositionX(character), dbObjectPositionY(character), dbObjectPositionZ(character) );
dbMoveObject(i,mobs[i-firstEnemies].velocityEnemies );
if(mobs[i-firstEnemies].speedFire==0) {
mobs[i-firstEnemies].speedFire=speedFireEnemy;
//srand(dbTimer());
mobs[i-firstEnemies].accuracyX=randFloatRange(-10,10);
mobs[i-firstEnemies].accuracyY=randFloatRange(-10,10);
mobs[i-firstEnemies].accuracyZ=randFloatRange(-10,10);
dbPositionSound(soundFireBulletEnemy,dbObjectPositionX(mobs[i-firstEnemies].id),dbObjectPositionY(mobs[i-firstEnemies].id),dbObjectPositionZ(mobs[i-firstEnemies].id));
dbPlaySound(soundFireBulletEnemy);
mobsAttack(mobs[i-firstEnemies].id,0);
}
else {
mobs[i-firstEnemies].speedFire--;
}
break;
case 4:
dbYRotateObject(i,dbObjectAngleY(character));
dbMoveObject(i,mobs[i-firstEnemies].velocityEnemies*3.5);
break;
/*default:
dbMoveObject(i,mobs[i-firstEnemies].velocityEnemies );*/
}
if(mobs[i-firstEnemies].timeMove>0) {
mobs[i-firstEnemies].timeMove--;
}
if(mobs[i-firstEnemies].timeIdle>0) {
mobs[i-firstEnemies].timeIdle--;
}
float x = dbObjectPositionX(i);
float y = dbObjectPositionY(i);
float z = dbObjectPositionZ(i);
float fHeight = dbGetTerrainGroundHeight( 1, dbObjectPositionX(i), dbObjectPositionZ(i) );
dbPositionObject( i, dbObjectPositionX(i), fHeight + 2.0f, dbObjectPositionZ(i) );
//float y = dbObjectPositionY(i);
int collide = SC_SphereSlide( 0, oldx,oldy,oldz, x,y,z, littleRadius, i );
//int collide = SC_SphereSlideGroup( 0, oldx,oldy,oldz, x,y,z, littleRadius, i );
if ( collide > 0 ) {
float x1 = SC_GetCollisionSlideX();
float y1 = SC_GetCollisionSlideY();
float z1 = SC_GetCollisionSlideZ();
dbPositionObject( i, SC_GetCollisionSlideX(),SC_GetCollisionSlideY(),SC_GetCollisionSlideZ() );
}
SC_UpdateObject( i );
}
}
}
Have you have any solution?
Thanks!