SA-MP Forums Archive
[HELP] How to find the angle to set player's front for a certain position? - 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: [HELP] How to find the angle to set player's front for a certain position? (/showthread.php?tid=96050)



[HELP] How to find the angle to set player's front for a certain position? - BRAZUCA - 06.09.2009

I need a function as SetPlayerLookAt...

This function is not SetPlayerCameraLookAt that change the position of the player's camera while SetPlayerLookAt should change the player's angle, in other words, the function should turn the player's front for a certain position.

Thanks and sorry bad english...


Re: [HELP] How to find the angle to set player's front for a certain position? - Takumi.WS - 06.09.2009

SetPlayerFacingAngle ?


Re: [HELP] How to find the angle to set player's front for a certain position? - BRAZUCA - 06.09.2009

SetPlayerFacingAngle(playerid,angle) change the angle of player based on angle informed

I need this a function as:

SetPlayerFacingAngleEx(playerid,x,y) that change the angle of player based on position where the player should be turned


Re: [HELP] How to find the angle to set player's front for a certain position? - Zeex - 06.09.2009

pawn Код:
stock SetPlayerLookAt(playerid, Float:X, Float:Y)
{
    new
      Float:pX,
      Float:pY,
      Float:pZ;
    GetPlayerPos(playerid, pX, pY, pZ);
    return SetPlayerFacingAngle(playerid, -acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
}



Re: [HELP] How to find the angle to set player's front for a certain position? - BRAZUCA - 06.09.2009

Thanks for reply, but something is wrong...
Look this image /imageshack/img215/9972/imagemso.jpg
I tried to turn the player for the vehicle position




Re: [HELP] How to find the angle to set player's front for a certain position? - BRAZUCA - 07.09.2009

Somebody can verify that, I really don't understand this function type...


Re: [HELP] How to find the angle to set player's front for a certain position? - Zeex - 07.09.2009

Oh, acos and SetPlayerFacingAngle tick the angle from different axes, so we need a little push it.
I've edited that function above and tested, should work.


Re: [HELP] How to find the angle to set player's front for a certain position? - brazzucas - 07.09.2009

I found that by Webflashing on http://forum.sa-mp.com/index.php?top...9696#msg479696

I think that will help if the rotation Z of the objects is the same thing of the ANGLE for the players

pawn Код:
stock SetObjectToFaceCords(objectid, Float:x1, Float:y1, Float:z1)
{

    new Float:x2,Float:y2,Float:z2;
    GetObjectPos(objectid, x2,y2,z2);

    new Float:DX = floatabs(x2-x1);
    new Float:DY = floatabs(y2-y1);
    new Float:DZ = floatabs(z2-z1);

  new Float:yaw = 0;
  new Float:pitch = 0;

    if(DY == 0 || DX == 0)
    {
      if(DY == 0 && DX > 0) {
            yaw = 00;
            pitch = 0; }
        else if(DY == 0 && DX < 0) {
            yaw = 180;
            pitch = 180; }
        else if(DY > 0 && DX == 0) {
            yaw = 90;
            pitch = 90; }
        else if(DY < 0 && DX == 0) {
            yaw = 270;
            pitch = 270; }
        else if(DY == 0 && DX == 0) {
            yaw = 0;
            pitch = 0; }
    }
    else
    {
        yaw = atan(DX/DY);
        pitch = atan(floatsqroot(DX*DX + DZ*DZ) / DY);
        if(x1 > x2 && y1 <= y2) {
          yaw = yaw + 90;
            pitch = pitch - 45; }
    else if(x1 <= x2 && y1 < y2) {
          yaw = 90 - yaw;
            pitch = pitch - 45; }
    else if(x1 < x2 && y1 >= y2) {
          yaw = yaw - 90;
            pitch = pitch - 45; }
    else if(x1 >= x2 && y1 > y2) {
          yaw = 270 - yaw;
            pitch = pitch + 315; }
    if(z1 < z2)
          pitch = 360-pitch;
    }
    SetObjectRot(objectid, 0, 0, yaw);
    SetObjectRot(objectid, 0, pitch, yaw+90);
}