SA-MP Forums Archive
Spawn Object Behind Player - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Spawn Object Behind Player (/showthread.php?tid=82786)



Spawn Object Behind Player - Yuryfury - 20.06.2009

I already have the command set up.

The problem is how do you spawn and object (Like an explosive barrel) behind a player no matter which direction they are facing?

Thanks in advance!


Re: Spawn Object Behind Player - mamorunl - 20.06.2009

you need to get the facing angle of the person. use the function 'GetXYInFrontOfPlayer'. It can be found on this forum


Re: Spawn Object Behind Player - Grim_ - 20.06.2009

Here are a few of them, I had in hand
pawn Код:
stock GetXYInFrontOfPlayer(playerid,&Float:x,&Float:y,Float:dis)
{
    new Float:pos[3];
    GetPlayerPos(playerid,pos[0],pos[1],pos[2]);
    GetPlayerFacingAngle(playerid,pos[2]);
    GetXYInFrontOfPoint(pos[0],pos[1],x,y,pos[2],dis);
}

stock GetXYBehindPlayer(playerid,&Float:x,&Float:y,Float:dis)
{
    new Float:pos[3];
    GetPlayerPos(playerid,pos[0],pos[1],pos[2]);
    GetPlayerFacingAngle(playerid,pos[2]);
    GetXYBehindPoint(pos[0],pos[1],x,y,pos[2],dis);
}

stock GetXYInFrontOfPoint(Float:x,Float:y,&Float:x2,&Float:y2,Float:angle,Float:distance)
{
    x2 = x + (distance * floatsin(-angle,degrees));
    y2 = y + (distance * floatcos(-angle,degrees));
}

stock GetXYBehindPoint(Float:x,Float:y,&Float:x2,&Float:y2,Float:angle,Float:distance)
{
    x2 = x - (distance * floatsin(-angle,degrees));
    y2 = y - (distance * floatcos(-angle,degrees));
}