I'm trying to do a line of sight calculation where I take the location of one character and see if it can see another character or if there's a wall in the way. I tried that static line of sight function but that didn't work, probably because the walls don't use static collision boxes (it's just one big wall object with polygonal collision detection). Next I tried creating a triangle with 2 of its vertices near the one character and one near the other and then checking if it collides with the wall object. Visually, it looks like what it's supposed to (basically a line coming out from the one character and ending at the other) but it never seems to be able to tell if it goes through a wall. Here's the code:
dbMakeObjectTriangle (LINEOFSIGHT, x - 2, dbObjectPositionY(id), z - 2, tarx, dbObjectPositionY(enemyTarget) + 2, tarz, x + 2, dbObjectPositionY(id), z + 2);
dbSetObjectCollisionToPolygons(LINEOFSIGHT);
dbSetObjectCollisionOn(LINEOFSIGHT);
if (dbObjectCollision(LINEOFSIGHT, WALLS) == 0) gotoAttackState();
dbDeleteObject(LINEOFSIGHT);
This code always results in the character going into attack state, even when there is clearly a wall in between it and its target (I froze the game and displayed the triangle for a few seconds after it was created to make sure of this). Any ideas how I could get this code to work or use other functions to accomplish the line of sight calculation? Thanks.