SA-MP Forums Archive
Teleport to facing angle. - 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: Teleport to facing angle. (/showthread.php?tid=602072)



Teleport to facing angle. - danielpalade - 01.03.2016

I'm trying to make the command /ff which would teleport you like 10 meters to where you where looking at.
Let's say I was looking in front of me, and I would use /ff it would teleport me 10 meters in the direction I was looking at.
The thing is, I have no idea how to do so..


Re: Teleport to facing angle. - AbyssMorgan - 01.03.2016

PHP Code:
CMD:ff(playerid){
    new 
Float:xFloat:yFloat:zFloat:rxFloat:rzFloat:txFloat:tyFloat:tz;
    
GetPlayerPos(playerid,x,y,z);
    
GetPlayerCameraRotation(playerid,rx,rz);
    
GetPointInFront3D(x,y,z,rx,rz,10.0,tx,ty,tz);
    
SetPlayerPos(playerid,tx,ty,tz);
    return 
1;

Include:
3DTryg.inc


Re: Teleport to facing angle. - [NWA]Hannes - 01.03.2016

Updated code, might work better.

pawn Code:
CMD:ff(playerid, params)
{
    new Float:fPX, Float:fPY, Float:fVX, Float:fVY, Float:object_x, Float:object_y, Float:player_x, Float:player_y, Float:player_z;
 
    const Float:fScale = 10.0;
 
    GetPlayerCameraPos(playerid, fPX, fPY, player_z); //Ignore player_z here
    GetPlayerCameraFrontVector(playerid, fVX, fVY, player_z); //Ignore player_z here
 
    object_x = fPX + floatmul(fVX, fScale);
    object_y = fPY + floatmul(fVY, fScale);
 
    GetPlayerPos(playerid, player_x, player_y, player_z);
    SetPlayerPos(playerid, object_x, object_y, player_z);
 
    return 1;
}
Won't work great if you're looking into the ground.