Making an actor face the player
#1

How can I make an actor face the player's direction?
Reply
#2

http://forum.sa-mp.com/showpost.php?...62&postcount=9
https://sampwiki.blast.hk/wiki/SetActorFacingAngle
Reply
#3

pawn Код:
stock Float:SetPlayerFacePlayer(playerid, faceplayerid)
{
    new Float:Px, Float:Py, Float: Pa;
    GetPlayerPos(playerid, Px, Py, Pa);
    new Float:fpX, Float:fpY, Float: fpZ;
    GetPlayerPos(faceplayerid, fpX, fpY, fpZ);
    Pa = floatabs(atan((fpY-Py)/(fpX-Px)));
    if(fpX <= Px && fpY >= Py) Pa = floatsub(180, Pa);
    else if(fpX < Px && fpY < Py) Pa = floatadd(Pa, 180);
    else if(fpX >= Px && fpY <= Py) Pa = floatsub(360.0, Pa);
    Pa = floatsub(Pa, 90.0);
    if(Pa >= 360.0) Pa = floatsub(Pa, 360.0);
    if(!IsPlayerInAnyVehicle(playerid)) SetPlayerFacingAngle(playerid, Pa);
    else SetVehicleZAngle(GetPlayerVehicleID(playerid), Pa);
    return Pa;
}
Not made by me.

Alter it to work with actors.
Reply
#4

Quote:
Originally Posted by MP2
Посмотреть сообщение
pawn Код:
stock Float:SetPlayerFacePlayer(playerid, faceplayerid)
{
    new Float:Px, Float:Py, Float: Pa;
    GetPlayerPos(playerid, Px, Py, Pa);
    new Float:fpX, Float:fpY, Float: fpZ;
    GetPlayerPos(faceplayerid, fpX, fpY, fpZ);
    Pa = floatabs(atan((fpY-Py)/(fpX-Px)));
    if(fpX <= Px && fpY >= Py) Pa = floatsub(180, Pa);
    else if(fpX < Px && fpY < Py) Pa = floatadd(Pa, 180);
    else if(fpX >= Px && fpY <= Py) Pa = floatsub(360.0, Pa);
    Pa = floatsub(Pa, 90.0);
    if(Pa >= 360.0) Pa = floatsub(Pa, 360.0);
    if(!IsPlayerInAnyVehicle(playerid)) SetPlayerFacingAngle(playerid, Pa);
    else SetVehicleZAngle(GetPlayerVehicleID(playerid), Pa);
    return Pa;
}
Not made by me.

Alter it to work with actors.
Done, thanks.

If anyone needs it

Код:
stock SetActorFacePlayer(actorid, faceplayerid)
{
	new Float:Px, Float:Py, Float: Pa;
	GetActorPos(actorid, Px, Py, Pa);
	new Float:fpX, Float:fpY, Float: fpZ;
	GetPlayerPos(faceplayerid, fpX, fpY, fpZ);
	Pa = floatabs(atan((fpY-Py)/(fpX-Px)));
	if(fpX <= Px && fpY >= Py) Pa = floatsub(180, Pa);
	else if(fpX < Px && fpY < Py) Pa = floatadd(Pa, 180);
	else if(fpX >= Px && fpY <= Py) Pa = floatsub(360.0, Pa);
	Pa = floatsub(Pa, 90.0);
	if(Pa >= 360.0) Pa = floatsub(Pa, 360.0);
	SetActorFacingAngle(actorid, Pa);
}
Reply
#5

Код:
SetActorToFacePlayer(actorid, targetid) {
    new
        Float: pX,
        Float: pY,
        Float: tX,
        Float: tY
    ;
    return
        GetPlayerPos(targetid, tX, tY, Float: targetid) &&
        GetActorPos(actorid, pX, pY, Float: targetid) &&
        SetActorFacingAngle(actorid, -atan2(tX - pX, tY - pY))
    ;
}
By Nero_3D
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)