#### Kentae

##### Member

As the title suggest it is quite unprecise, or rather, it seems to think that the triangle is 10-15 pixels thick.

Here are some example pictures:

The point is represented by the small cube that is only 1 pixel wide/deep/tall. (the cube shape is not part of the calculation. It was just a simple way of visualizing the point)

If you look at the triangle plane head on like in the first two pictures the collision is completley precise.

But if you have a look at the collision from the side like in the next two pics you'll see how unprecise the collision is.

As you can see in the last picture, the cube that represents the point turns red (indicating that there is a collision) waaay before it hits the triangle plane.

Here's the code:

GML:

```
/// @desc kt_collision_point_tri()
/// @param point_x
/// @param point_y
/// @param point_z
/// @param tri_x1
/// @param tri_y1
/// @param tri_z1
/// @param tri_x2
/// @param tri_y2
/// @param tri_z2
/// @param tri_x3
/// @param tri_y3
/// @param tri_z3
// Get user input.
// Get the coordinates of the point and of the three vetecies that make up the triangle.
var px = argument0;
var py = argument1;
var pz = argument2;
var tx1 = argument3;
var ty1 = argument4;
var tz1 = argument5;
var tx2 = argument6;
var ty2 = argument7;
var tz2 = argument8;
var tx3 = argument9;
var ty3 = argument10;
var tz3 = argument11;
// Subtract the position of the point from the triangle's vertecies.
// We do this so that we can use the origin of the world as the point.
// This just makes the calculation easier.
tx1 -= px;
ty1 -= py;
tz1 -= pz;
tx2 -= px;
ty2 -= py;
tz2 -= pz;
tx3 -= px;
ty3 -= py;
tz3 -= pz;
// Now we are going to pretend that the triangle and the point make up a pyramid.
// We then get the normals of the walls of this pyramid.
var u = cross_product( tx2, ty2, tz2, tx3, ty3, tz3 );
var v = cross_product( tx3, ty3, tz3, tx1, ty1, tz1 );
var w = cross_product( tx1, ty1, tz1, tx2, ty2, tz2 );
// now we check if those normals point in the same direction.
// Return false if they do not.
if ( dot_product_3d( u[0], u[1], u[2], v[0], v[1], v[2] ) < 0 )
{
return false;
}
if ( dot_product_3d( u[0], u[1], u[2], w[0], w[1], w[2] ) < 0 )
{
return false;
}
// If all normals are pointing in the same direction, return true.
return true;
```

Any help would be greatly appreciated

Edit: the cross_product script is one I wrote myself too but that one has been tested propely and works as it should.