Determine the point you're looking at - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Determine the point you're looking at (
/showthread.php?tid=342037)
Determine the point you're looking at -
Padarom - 12.05.2012
Hello everybody,
I want to create something like a rocket which shoots in the direction I look and explodes as soon as it colides.
The movement and explosion is no problem (Thus MoveObject returns the time the movement takes), but I have problems in determining the coordinates of the point I'm looking at.
The only way I could think of is with MapAndreas which I'm using already, but I have still can't figure out how to calculate the proper position.
I hope you understand my problem and are able to help me.
Regards
Padarom
Re: Determine the point you're looking at -
vassilis - 12.05.2012
not sure:
pawn Код:
stock IsPlayerLookingAtPoint(playerid,Float:X,Float:Y,Float:Z,Float:Distance,RadiosToPoint)
{
new Float:CX,Float:CY,Float:CZ,Float:FX,Float:FY,Float:FZ;
new Float:PX,Float:PY,Float:PZ,Float:D;
if(IsPlayerInRangeOfPoint(playerid,Distance,X ,Y ,Z))
{
GetPlayerCameraPos(playerid,CX,CY,CZ);
GetPlayerCameraFrontVector(playerid, FX, FY, FZ);
PX = FX*D+CX;
PY = FY*D+CY;
PZ = FZ*D+CZ;
D = floatsqroot(((PX - X) * (PX - X)) + ((PY - Y) * (PY - Y)) + ((PZ - Z) * (PZ - Z)));
if(D < RadiosToPoint)
{
return 1;
}
}
return 0;
}
and then use at the command:
pawn Код:
new Float:x,Float:y,Float:z;
if(IsPlayerLookingAtPoint(Float:x,Float:y,Float:z,etc);
MoveObject(model,Float:x,Float:y,Float:Z);
not sure if it will work
it's just a sort out of how you would implement it