Detecting something infront of you - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Detecting something infront of you (
/showthread.php?tid=122016)
Detecting something infront of you -
dice7 - 19.01.2010
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
Re: Detecting something infront of you -
boelie - 19.01.2010
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
Re: Detecting something infront of you -
dice7 - 19.01.2010
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