GetAimingPos -
Trooper[Y] - 12.08.2010
Hey there.
I need your help.
I found some snippets with the function "IsPlayerAimingAt",
but that doesnt helps me in any way.
So, i want to get the coordinates to the position, where the player is aiming to.
I think i saw something like that before, where pickups had been created in front of the player to show the line of sight with a weapon.
Waiting for you answer,
Trooper
Re: GetAimingPos -
Trooper[Y] - 12.08.2010
Got this snippet from a fs:
[code]
new Float:gtpos[50];
GetPlayerCameraPos(playerid,gtpos[0],gtpos[1],gtpos[2]);
GetPlayerCameraFrontVector(playerid,gtpos[3],gtpos[4],gtpos[5]);
for(new checkdist=0;checkdist<=50;checkdist+=10)
{
marker[playerid][checkdist] = CreatePickup(1239,23,gtpos[3]*checkdist+gtpos[0],gtpos[4]*checkdist+gtpos[1],gtpos[5]*checkdist+gtpos[2]);
}
[code]
The problem is, that its not exact, sometimes lowers, even i aimed upwards, or is too low.
replace "or" with "and"...
Re: GetAimingPos -
Trooper[Y] - 13.08.2010
//bumper
Re: GetAimingPos -
Hiddos - 13.08.2010
Can you show me your IsPlayerAimingAt function? The solution is in that command.
Re: GetAimingPos -
Trooper[Y] - 13.08.2010
Quote:
Float: DistanceCameraTargetToLocation(Float:CamX, Float:CamY, Float:CamZ, Float:ObjX, Float:ObjY, Float:ObjZ, Float:FrX, Float:FrY, Float:FrZ) {
new Float:TGTDistance;
// get distance from camera to target
TGTDistance = floatsqroot((CamX - ObjX) * (CamX - ObjX) + (CamY - ObjY) * (CamY - ObjY) + (CamZ - ObjZ) * (CamZ - ObjZ));
new Float:tmpX, Float:tmpY, Float:tmpZ;
tmpX = FrX * TGTDistance + CamX;
tmpY = FrY * TGTDistance + CamY;
tmpZ = FrZ * TGTDistance + CamZ;
return floatsqroot((tmpX - ObjX) * (tmpX - ObjX) + (tmpY - ObjY) * (tmpY - ObjY) + (tmpZ - ObjZ) * (tmpZ - ObjZ));
}
stock IsPlayerAimingAt(playerid, Float: x, Float:y, Float:z, Float:radius)
{
new Float:cx,Float:cy,Float:cz,Float:fx,Float:fy,Float :fz;
GetPlayerCameraPos(playerid, cx, cy, cz);
GetPlayerCameraFrontVector(playerid, fx, fy, fz);
return (radius >= DistanceCameraTargetToLocation(cx, cy, cz, x, y, z, fx, fy, fz));
}
|
This is what i now got:
Quote:
new Float:gtpos[50];
GetPlayerCameraPos(playerid,gtpos[0],gtpos[1],gtpos[2]);
GetPlayerCameraFrontVector(playerid,gtpos[3],gtpos[4],gtpos[5]);
for(new checkdist=0;checkdist<=50;checkdist+=5)
{
gtpos[6] = gtpos[0] + floatmul(gtpos[3], float(checkdist));
gtpos[7] = gtpos[1] + floatmul(gtpos[4], float(checkdist));
gtpos[8] = gtpos[2] + floatmul(gtpos[5], float(checkdist));
marker[playerid][checkdist] = CreatePickup(1239,23,gtpos[6],gtpos[7],gtpos[8]);
}
|
The problem is, that it work fine, if im not aiming somewhere...
If i use a weapon to aime somewhere, its getting wrong...
Re: GetAimingPos -
iggy1 - 13.08.2010
This topic should help it works for me for placing objects you would just need to edit to what you need ie, just return co-ords not create object.
Here is the code posted by simon in that topic.
pawn Код:
new
Float:fPX, Float:fPY, Float:fPZ,
Float:fVX, Float:fVY, Float:fVZ,
Float:object_x, Float:object_y, Float:object_z;
// Change this constant to the the scale you want. A larger scale increases the distance from
// the camera. A negative scale will inverse the vectors and make them face in the opposite
// direction (i.e. behind the camera)
const
Float:fScale = 6.0;
GetPlayerCameraPos(playerid, fPX, fPY, fPZ);
GetPlayerCameraFrontVector(playerid, fVX, fVY, fVZ);
object_x = fPX + floatmul(fVX, fScale);
object_y = fPY + floatmul(fVY, fScale);
object_z = fPZ + floatmul(fVZ, fScale);
CreateObject(345, object_x, object_y, object_z, 0.0, 0.0, 0.0);
Its camera angle that effects it though not aiming.
Re: GetAimingPos -
Trooper[Y] - 22.08.2010
Thats the problem.
Without aiming my other way also works.
But if i aim, its getting wrong...
Re: GetAimingPos -
Trooper[Y] - 29.08.2010
//bumper
AW: GetAimingPos -
Trooper[Y] - 29.09.2010
//bumper again...
Re: GetAimingPos -
Mauzen - 29.09.2010
When aiming with weapon, there is a offset to the FrontVector, because the camera zooms in and the player is moved a bit to the left of the screen. You can minimize the offset by adding/subtracting a specific angle to the rotation and z-angle of the FrontVector (calc the angles from the vector first with atan). Hard to explain, youll have to experiment a bit with the angles, dont know if someone else beside me did this yet.
Ive got a precise include for this, but sorry, i wont release it as long as i am working on a gm that uses it.