IsVehicleInFrontOfVehicle(veh1, veh2, range)
#1

Has anybody the code from the title?

IsVehicleInFrontOfVehicle(veh1, veh2, range)
Reply
#2

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
Reply
#3

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
Reply
#4

@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.
Reply
#5

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
Reply
#6

I never said it was wrong lol.
Reply
#7

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
Reply
#8

I never posted any code where is fuck 30.0 is coming from
Reply
#9

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...
Reply
#10

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.

Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)