[help] make the camera rotate around a player
#1

Hello,

I wanted to make the camera rotate around a player when he is in class selection
I've done a big part already but it won't really work like how I want it to ><

here is what I have:

pawn Код:
new Float:CameraAngle[MAX_PLAYERS];
new Float:CameraPosX[MAX_PLAYERS];
new Float:CameraPosY[MAX_PLAYERS];

forward HoldKey(playerid);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public HoldKey(playerid)
{
    SendClientMessage(playerid, COLOR_GREY, "HoldKey");
    new keys, updown, leftright;
    GetPlayerKeys(playerid, keys, updown, leftright);

    if(keys == KEY_CROUCH ) //left
    {
        if(PlayerInClassSelection[playerid] == true)
        {
          CameraAngle[playerid] = floatsub(CameraAngle[playerid],0.5);
          GetXYForCamera(CameraPosX[playerid], CameraPosY[playerid], CameraAngle[playerid]);
          SetPlayerCameraPos(playerid, CameraPosX[playerid], CameraPosY[playerid],11.5529);
          SetPlayerCameraLookAt(playerid, 2087.9612,1910.0950,12.4536);
        }
    }
    if(keys == KEY_JUMP ) //right
    {
        if(PlayerInClassSelection[playerid] == true)
        {
          CameraAngle[playerid] = floatadd(CameraAngle[playerid],0.5);
          GetXYForCamera(CameraPosX[playerid], CameraPosY[playerid], CameraAngle[playerid]);
          SetPlayerCameraPos(playerid, CameraPosX[playerid], CameraPosY[playerid],11.5529);
          SetPlayerCameraLookAt(playerid, 2087.9612,1910.0950,12.4536);
        }
    }
    if (keys > 0) SetTimerEx("HoldKey", 50, 0, "d", playerid);
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    SetTimerEx("HoldKey", 50, 0, "d", playerid);

    if(newkeys == KEY_CROUCH ) //left
    {
        if(PlayerInClassSelection[playerid] == true)
        {
          CameraAngle[playerid] = floatsub(CameraAngle[playerid],0.5);
          GetXYForCamera(CameraPosX[playerid], CameraPosY[playerid], CameraAngle[playerid]);
          SetPlayerCameraPos(playerid, CameraPosX[playerid], CameraPosY[playerid],11.5529);
          SetPlayerCameraLookAt(playerid, 2087.9612,1910.0950,12.4536);
        }
    }
    if(newkeys == KEY_JUMP ) //right
    {
        if(PlayerInClassSelection[playerid] == true)
        {
          CameraAngle[playerid] = floatadd(CameraAngle[playerid],0.5);
          GetXYForCamera(CameraPosX[playerid], CameraPosY[playerid], CameraAngle[playerid]);
          SetPlayerCameraPos(playerid, CameraPosX[playerid], CameraPosY[playerid],11.5529);
          SetPlayerCameraLookAt(playerid, 2087.9612,1910.0950,12.4536);
        }
    }
    return 1;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public OnPlayerRequestClass(playerid, classid)
{
  SetPlayerPos(playerid, 2087.4019,1911.1284,12.4434);
  SetPlayerFacingAngle(playerid, 251.7306);
  SetPlayerCameraPos(playerid, 2092.0486,1909.7275,11.5529);
  SetPlayerCameraLookAt(playerid, 2087.9612,1910.0950,12.4536);
  CameraAngle[playerid] = 251.7306;
  CameraPosX[playerid] = 2092.0486;
  CameraPosY[playerid] = 1909.727;
  PlayerInClassSelection[playerid] = true;
  return 1;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

GetXYForCamera(&Float:x, &Float:y, Float:angle)
{
    new Float:distance = 3.0;
    x += (distance * floatsin(-angle, degrees));
    y += (distance * floatcos(-angle, degrees));
}
the problem is that the camera doesn't rotate around the player, but it makes a large circle over all las venturas

//edit: pastebin link: http://pastebin.com/f29047ac4
Reply
#2

maybe replace
Код:
if(keys == KEY_CROUCH )
with
Код:
if(keys & KEY_CROUCH )
and
Код:
if(keys == KEY_JUMP )
with
Код:
if(keys & KEY_JUMP )
edit:
hmm, not your problem, I'm not that good at maths, so I can't help you with that
Reply
#3

but that works

the calculation of the camera pos won't work good
it should rotate around the player but it doesn't
Reply
#4

is it correct that OnPlayerKetStateChange isn't detected in class selection? -_-
all this work for nothing

//edit: sorry for dubblepost
Reply
#5

Quote:
Originally Posted by °ғαιιοцт°
is it correct that OnPlayerKetStateChange isn't detected in class selection? -_-
all this work for nothing

//edit: sorry for dubblepost
I think it is as when you type MAJ it makes you spawn
Reply
#6

yes I know, but OnPlayerKeyStateChange isn't called there
Reply
#7

Well, making a rotation with commands would be possible but i guess nobody would bother typing /ROTATE IT NOW!! Just suggesting though ;p
Reply
#8

Quote:
Originally Posted by [NT
Extremo ]
Well, making a rotation with commands would be possible but i guess nobody would bother typing /ROTATE IT NOW!! Just suggesting though ;p
rofl I'd rofl when i see that on a server
imagine it >< type /camera right to move 5° to the right and /camera left to move 5° left

//i deleted the code now because i coudn't use it anymore
Reply
#9

Why don't you try with a menu then?
Reply
#10

Quote:
Originally Posted by Coicatak
Why don't you try with a menu then?
how then?
(using a menu to rotate around a player? )
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)