Facing Angle
#1

Any ideas how to make the player stare at other player near him?
i made something like this: but doesn't work perfectly!

pawn Код:
new Float:a, targetid;
GetPlayerFacingAngle(targetid, a);
SetPlayerFacingAngle(playerid, -a);
Reply
#2

Well, how do you get "targetid"'s value? And how doesn't it work perfectly?
Reply
#3

pawn Код:
SetPlayerToFacePlayer(playerid, targetid)
{

    new
        Float:pX,
        Float:pY,
        Float:pZ,
        Float:X,
        Float:Y,
        Float:Z,
        Float:ang;

    if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetid)) return 0;

    GetPlayerPos(targetid, X, Y, Z);
    GetPlayerPos(playerid, pX, pY, pZ);

    if( Y > pY ) ang = (-acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
    else if( Y < pY && X < pX ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 450.0);
    else if( Y < pY ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);

    if(X > pX) ang = (floatabs(floatabs(ang) + 180.0));
    else ang = (floatabs(ang) - 180.0);
   
    SetPlayerFacingAngle(playerid, ang);

    return 0;

}//include a_angles
Look this
Reply
#4

Quote:
Originally Posted by DiGiTaL_AnGeL
Посмотреть сообщение
Well, how do you get "targetid"'s value? And how doesn't it work perfectly?
nevermind about that, i'm using the targetid in some cmd and i want to add this feature and wanna know how could it work!

@ViniBorn do i have to download a .inc file for this!!
Reply
#5

You don't need to download anything, only use that code...
Reply
#6

Well I don't know why this function still gets spread but I think people don't know it better, this code is enough
pawn Код:
SetPlayerToFacePlayer(playerid, targetid) {
    new
        Float: pX,
        Float: pY,
        Float: tX,
        Float: tY
    ;
    return
        GetPlayerPos(targetid, tX, tY, Float: targetid) &&
        GetPlayerPos(playerid, pX, pY, Float: targetid) &&
        SetPlayerFacingAngle(playerid, -atan2(tX - pX, tY - pY))
    ;
}
Reply
#7

Quote:
Originally Posted by ViniBorn
Посмотреть сообщение
You don't need to download anything, only use that code...
there are no errors on compiling.
but when using it in the cmd:

Код:
(1533) : warning 219: local variable "pX" shadows a variable at a preceding level
(1533) : warning 219: local variable "pY" shadows a variable at a preceding level
(1533) : warning 219: local variable "pZ" shadows a variable at a preceding level
(1537) : error 035: argument type mismatch (argument 2)
(1539) : warning 213: tag mismatch
(1539) : warning 213: tag mismatch
(1539) : warning 213: tag mismatch
(1539) : warning 213: tag mismatch
(1539) : warning 213: tag mismatch
(1539) : warning 213: tag mismatch
(1540) : warning 213: tag mismatch
(1540) : warning 213: tag mismatch
(1540) : warning 213: tag mismatch
(1540) : warning 213: tag mismatch
(1540) : warning 213: tag mismatch
(1540) : warning 213: tag mismatch
(1540) : warning 213: tag mismatch
(1541) : warning 213: tag mismatch
(1541) : warning 213: tag mismatch
(1541) : warning 213: tag mismatch
(1541) : warning 213: tag mismatch
(1541) : warning 213: tag mismatch
(1541) : warning 213: tag mismatch
(1543) : warning 213: tag mismatch
(1533) : warning 203: symbol is never used: "pZ"
(1533) : warning 203: symbol is never used: "pY"
(1533) : warning 203: symbol is never used: "pX"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
@Nero_3D Also no errors on compiling but when using it:
Код:
(1552) : warning 219: local variable "pX" shadows a variable at a preceding level
(1553) : warning 219: local variable "pY" shadows a variable at a preceding level
(1558 -- 1559) : error 035: argument type mismatch (argument 2)
(1553) : warning 203: symbol is never used: "pY"
(1552) : warning 203: symbol is never used: "pX"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Reply
#8

These warning and errors appear because you already have a variable called pX and pY declared as global
I won't tell you how to name your global variables but I advise you to add some indicator like the letter 'g' at the beginning

To fix that without changing any of your code just rename the local variables (from 'p' to 'a')
pawn Код:
SetPlayerToFacePlayer(playerid, targetid) {
    new
        Float: aX,
        Float: aY,
        Float: tX,
        Float: tY
    ;
    return
        GetPlayerPos(targetid, tX, tY, Float: targetid) &&
        GetPlayerPos(playerid, aX, aY, Float: targetid) &&
        SetPlayerFacingAngle(playerid, -atan2(tX - aX, tY - aY))
    ;
}
Reply
#9

thanks didn't notice that! compiling with no errors but not tested yet!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)