Quote:
stock
GetXYZInViewOfPlayer(playerid, &Float:X, &Float:Y, &Float:Z, Float:distance)
{
new Float:VX, Float:VY, Float:VZ;
GetPlayerPos(playerid, X, Y, Z);
GetPlayerCameraFrontVector(playerid, VX, VY, VZ);
X += (distance * VX);
Y += (distance * VY);
Z += (distance * VZ);
}
|
Hm I through about this function but I think it needs a little correction:
pawn Код:
stock GetXYZInViewOfPlayer(playerid, &Float:X, &Float:Y, &Float:Z, Float:distance)
{
new Float:VX, Float:VY, Float:VZ;
//GetPlayerPos(playerid, X, Y, Z);
GetPlayerCameraPos(playerid,X,Y,Z);
//I change this because the Cameravector starts from the CameraPos and not from the Player.
//If it would start from the Player the Cameravector would be a little bit different.
//Now you have to think that the distance you choose for this function is not from Player to a point,
//it is from the CameraPos... (Don't forget it)
GetPlayerCameraFrontVector(playerid, VX, VY, VZ);
//--[Correction of the CameraVector]----------------------------------------------
new Float:tmpfloat;
tmpfloat = floatdiv(1,floatsqroot(floatpower(VX,2)+floatpower(VY,2)+floatpower(VZ,2)));
// I don't know how it is called in english but in Germany we say "Betrag"
// With this calculation "floatsqroot(floatpower(VX,2)+floatpower(VY,2)+floatpower(VZ,2))" i know how long the vector is.
// For example the vector could be 2.34 feet/meter/inch long...
VX = floatmul(VX, tmpfloat);
VY = floatmul(VY, tmpfloat);
VZ = floatmul(VZ, tmpfloat);
// Now the cameravector is exactly 1 "distance" long...
// I calculate (1 div [How Long the vector is]) * [Vector] = [Vector which is 1 "distance" long]
//-------------------------------------------------------------------
X += (distance * VX);
Y += (distance * VY);
Z += (distance * VZ);
}
The image should explain my correction...
I.
GetPlayerCameraFrontVector returns the vector from the camera, but you can see that the vector which would start from the Player would be another like the "GetPlayerCameraFrontVector"... It's the reason why I change "GetPlayerPos" to "GetPlayerCameraPos"
II. I have done a "Correction of the CameraVector" because GetPlayerCameraFrontVector could return a vector which isn't 1 "Distance" long, so i have to change the normal cameravector to the modify cameravector...