Detecting something infront of you
#1

So, I have an object poiting at one direction (at a straight line)
I have 6 coords from that line (with GetXYInFrontOf... (the function works))
How could I detect if a vehicle isn't on that line

I tried taking one set of coords, dividing them (since the division should return the same, eg coords 1,1 and 2,2 will return 1)
and comparing them with the division of the vehicle coords (GetVehiclePos)
but it always says I'm not on the line

http://pastebin.com/m6f4c0abd
Reply
#2

Quote:

That's my IsPlayerAtPlayerDirection

omg thats a nice one :S i was trying to improve and try a bit with getxyinfrontofme and playerfacingplayer
but this is even better
Reply
#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


Forum Jump:


Users browsing this thread: 1 Guest(s)