17.03.2016, 01:46
IsObstacleOnPath
The function is very heavy.
If you know how optimize it, help me
Anyway, here a colission detect between two points
Diference between RayCastLine. IsObstacleOnPath detect only Colissions with 63.5 angle or above. Useful for NPCS path and other.
This version of IsObstacleOnPath works with Bridges and others "Coverage" .
Thank to Crayder. He taught me tips of CA_RayCastLineNormal
Ps. My English is Terrible
The function is very heavy.
If you know how optimize it, help me
Anyway, here a colission detect between two points
Diference between RayCastLine. IsObstacleOnPath detect only Colissions with 63.5 angle or above. Useful for NPCS path and other.
This version of IsObstacleOnPath works with Bridges and others "Coverage" .
Thank to Crayder. He taught me tips of CA_RayCastLineNormal
PHP код:
IsObstacleOnPath(Float:a[], Float:b[], Float:tolerance = 63.5, Float: pitch = 0.5) {
static Float:c[3];
if(floatabs(a[2] - b[2]) < 0.25) {
// if is same Z ground, only check CA_RayCastLine have simple colission
return CA_RayCastLine(
a[0], a[1], a[2],
b[0], b[1], b[2],
c[0], c[1], c[2]
);
}
static Float:d[3];
static Float: retn;
static Float:angle;
// angle between two points
angle = (atan2(a[0]-b[0], a[1]-b[1]))+180.0;
if(angle > 360.0) angle -= 360.0;
static Float: i; i = pitch;
// distance between two points 3d
static Float: j; j = VectorSize(a[0]-b[0], a[1]-b[1], 0.0);
new Float: x; new Float: y;
while( i <= (j) ) {
// check pitch by bitch to detect anormalite of Z ground (obstacle)
c[0]=a[0]+(i*floatsin(angle,degrees));
c[1]=a[1]+(i*floatcos(angle,degrees));
d[0]=a[0]+((i-pitch)*floatsin(angle,degrees));
d[1]=a[1]+((i-pitch)*floatcos(angle,degrees));
// get find z coord
CA_FindZ_For2DCoord(c[0],c[1],c[2]);
CA_FindZ_For2DCoord(d[0],d[1],d[2]);
i += pitch;
// get distance from 2d point
x = VectorSize(c[0]-d[0], c[1]-d[1], 0.0);
static Float: slope;
static Float: e[3];
static r ;
if(d[2]>=c[2]) {
// check if have possible colission
y = (d[2]-c[2]);
// get angle between z angle
retn = atan2(y,x);
// if have a colission
if(retn > tolerance) {
r = CA_RayCastLineNormal(
c[0], c[1], c[2],
d[0], d[1], c[2]+0.5,
e[0],e[1],e[2],
slope, slope, slope
);
// check if is bridge or not
return (r && acos(slope) > tolerance);
}
}
else {
y = floatabs(c[2]-d[2]);
retn = atan2(y,x);
if(retn > tolerance) {
r = CA_RayCastLineNormal(
d[0], d[1], d[2],
c[0], c[1], d[2]+0.5,
e[0],e[1],e[2],
slope, slope, slope
);
return (r && acos(slope) > tolerance);
}
}
}
return false;
}