15.01.2013, 03:03
As the title says;
Is it possible to determine if a vehicle passes the front of a player, and if so, how?
Is it possible to determine if a vehicle passes the front of a player, and if so, how?
if a vehicle passes the front of a player |
stock GetDistanceToCar(playerid, veh, Float: posX = 0.0, Float: posY = 0.0, Float: posZ = 0.0) {
new
Float: Floats[2][3];
if(posX == 0.0 && posY == 0.0 && posZ == 0.0) {
if(!IsPlayerInAnyVehicle(playerid)) GetPlayerPos(playerid, Floats[0][0], Floats[0][1], Floats[0][2]);
else GetVehiclePos(GetPlayerVehicleID(playerid), Floats[0][0], Floats[0][1], Floats[0][2]);
}
else {
Floats[0][0] = posX;
Floats[0][1] = posY;
Floats[0][2] = posZ;
}
GetVehiclePos(veh, Floats[1][0], Floats[1][1], Floats[1][2]);
return floatround(floatsqroot((Floats[1][0] - Floats[0][0]) * (Floats[1][0] - Floats[0][0]) + (Floats[1][1] - Floats[0][1]) * (Floats[1][1] - Floats[0][1]) + (Floats[1][2] - Floats[0][2]) * (Floats[1][2] - Floats[0][2])));
}
forward GetXYInFrontOfPlayer2(playerid, &Float, &Float:y, Float:distance, Float:angle);
public GetXYInFrontOfPlayer2(playerid, &Float, &Float:y, Float:distance, Float:angle) {
new Float:a;
GetPlayerPos(playerid, x, y, a);
GetPlayerFacingAngle(playerid, a);
if (GetPlayerVehicleID(playerid))
GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
a += angle;
x += (distance * floatsin(-a, degrees));
y += (distance * floatcos(-a, degrees));
}