Detecting something infront of you
#3

Thank you for your reply, but I can't seem to get it working. It always returns true, on every angle (well, I tried with 0.01, 1.0 and 20.5). Also tried switching the coords, like the comment shows

pawn Код:
IsVehicleInObjectDirection(vehicleid, Float:angle)
{
    /*
    new Float:px = object[0],
    Float:py = object[1],
    Float:pz = object[2];
   
    new Float:x,Float:y,Float:a;
    GetVehiclePos(vehicleid, x, y, a);
    */

   
    new Float:x = object[0],
    Float:y = object[1],
    Float:a = object[2];

    new Float:px,Float:py,Float:pz;
    GetVehiclePos(vehicleid, px, py, pz);

    a = floatabs(atan((py-y)/(px-x)));

    if (px <= x && py >= y)         a = floatsub(180, a);
    else if (px < x && py < y)      a = floatadd(a, 180);
    else if (px >= x && py <= y)    a = floatsub(360.0, a);

    a = floatsub(a, 90.0);

    if (a >= 360.0) a = floatsub(a, 360.0);

    if (a >= (a-angle) && a <= (a+angle)) return 1;
    return 0;
}
object[0], object[1] and object[2] being x, y and z coords.

edit:
trying with the a_angles include
Reply


Messages In This Thread
Detecting something infront of you - by dice7 - 19.01.2010, 20:17
Re: Detecting something infront of you - by boelie - 19.01.2010, 20:52
Re: Detecting something infront of you - by dice7 - 19.01.2010, 21:09

Forum Jump:


Users browsing this thread: 1 Guest(s)