03.10.2011, 15:31
After 30 Minites thinking I have now the solution to get the real position of the Petrolcap from the vehicle:
I lookat at the function:
if I now take the angle of the player and add 180° i get:
The only thing i have to do now is to add to the angle "a+=180" an other angle, which i get if I calculate the Angle with the tangent of OffSetY div OffSetX... Furthermore I change playerid to vehicleid because a player hasn't a Petrolcap :P
-----------------------------------------------------------------------------------
The finish Function looks like this:
Now it's really easy to use... Here is an Example
I lookat at the function:
pawn Код:
stock GetXYInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
new Float:a;
GetPlayerPos(playerid, x, y, a);
GetPlayerFacingAngle(playerid, a);
if (GetPlayerVehicleID(playerid))
{
GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
}
x += (distance * floatsin(-a, degrees));
y += (distance * floatcos(-a, degrees));
}
pawn Код:
stock GetXYInBehindOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
{
new Float:a;
GetPlayerPos(playerid, x, y, a);
GetPlayerFacingAngle(playerid, a);
if (GetPlayerVehicleID(playerid))
{
GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
}
a+=180;
x += (distance * floatsin(-a, degrees));
y += (distance * floatcos(-a, degrees));
}
-----------------------------------------------------------------------------------
The finish Function looks like this:
pawn Код:
stock GetXYZOfOffSetPositions(vehicleid,Float:OffSetX,Float:OffSetY,Float:OffSetZ,&Float:x, &Float:y, &Float:z)
{
new Float:a,Float:distance;
GetVehiclePos(vehicleid, x, y, z);
GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
a-=180.0+atan(OffSetY,OffSetX);
distance = floatsqroot(floatpower(OffSetX,2)+floatpower(OffSetY,2))
x += (distance * floatsin(-a, degrees));
y += (distance * floatcos(-a, degrees));
z += OffSetZ;
}
Код:
400 petrolcap -1.10 -2.06 -0.07
pawn Код:
public OnUnoccupiedVehicleUpdate(vehicleid, playerid, passenger_seat)
{
if(GetVehicleModel(vehicleid) == 400)
{
new Float:LookingPos[3];
GetXYZOfOffSetPositions(vehicleid,-1.10,-2.06,-0.07,LookingPos[0], LookingPos[1], LookingPos[2]);
// Now you only have to check if the player looks at the Position LookingPos[0], LookingPos[1], LookingPos[2]
// If the player do this, you know that he aims at the petrolcap ...
}
return 1;
}