SA-MP Forums Archive
IsVehicleInFrontOfVehicle(veh1, veh2, range) - 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)
+--- Thread: IsVehicleInFrontOfVehicle(veh1, veh2, range) (/showthread.php?tid=567342)



IsVehicleInFrontOfVehicle(veh1, veh2, range) - axi92 - 13.03.2015

Has anybody the code from the title?

IsVehicleInFrontOfVehicle(veh1, veh2, range)


Re: IsVehicleInFrontOfVehicle(veh1, veh2, range) - Pottus - 13.03.2015

Take a look at this function you would need to change it for vehicles which is very easy to do.

https://sampforum.blast.hk/showthread.php?tid=203797


AW: IsVehicleInFrontOfVehicle(veh1, veh2, range) - Kaliber - 13.03.2015

I just guess, write it like this:

PHP код:
stock IsVehicleInFrontOfVehicle(veh1veh2Float:range)
{
    new 
Float:a,Float:x,Float:y,Float:z;
    
GetVehiclePos(veh1,x,y,z);
    
GetVehicleZAngle(veh1a);
    
+= (range floatsin(-adegrees));
    
+= (range floatcos(-adegrees));
    return (
GetVehicleDistanceFromPoint(veh2,x,y,z) <= 3.0) ? true false;

Greekz


Re: IsVehicleInFrontOfVehicle(veh1, veh2, range) - Pottus - 13.03.2015

@Kaliber that is one way to do it except you made a small mistake.

pawn Код:
stock IsVehicleInFrontOfVehicle(veh1, veh2, Float:range = 5.0)
...
return (GetVehicleDistanceFromPoint(veh2,x,y,z) <= range) ? true : false;
That is a spherical check the other method is a cone shape I would choose the spherical check myself I think seems like the better method when I visualize it.


AW: Re: IsVehicleInFrontOfVehicle(veh1, veh2, range) - Kaliber - 13.03.2015

Quote:
Originally Posted by Pottus
Посмотреть сообщение
That is a circular check the other method is a cone shape.
No...my code is right.

Think about it, i add the range before.

And then i check, if the vehicle is in range of this point i added

Greekz


Re: IsVehicleInFrontOfVehicle(veh1, veh2, range) - Pottus - 13.03.2015

I never said it was wrong lol.


AW: Re: IsVehicleInFrontOfVehicle(veh1, veh2, range) - Kaliber - 13.03.2015

Quote:
Originally Posted by Pottus
Посмотреть сообщение
I never said it was wrong lol.
But your Code is wrong.

Think about it, the range is 30.0

Код:
o---o
|    | -----|//here is the other car (also distance 30.0 but not in front!!!)
o---o
|
|   //here is the distance of 30.0

Greekz


Re: IsVehicleInFrontOfVehicle(veh1, veh2, range) - Pottus - 13.03.2015

I never posted any code where is fuck 30.0 is coming from


AW: Re: IsVehicleInFrontOfVehicle(veh1, veh2, range) - Kaliber - 13.03.2015

Quote:
Originally Posted by Pottus
Посмотреть сообщение
I never posted any code where is fuck 30.0 is coming from
It's just an example...

when you do it like you did, you can't check if the vehicle is in front or back or at the side...


Re: IsVehicleInFrontOfVehicle(veh1, veh2, range) - Pottus - 13.03.2015

Maybe it is just preference but when I visualize checking if an object or a player is front of another player using a sphere feels more natural. That is not to dismiss using a conic check it is really preference one way may work better than the other.