Move camera next to the player
#6

This is a code I have just quickly whipped up:
pawn Код:
stock SetCameraNextToPlayer(playerid, Float:distance, Float:offset)
{
    new Float:x, Float:y, Float:z, Float:a;
    GetPlayerPos(playerid, x, y, z);
    GetPlayerFacingAngle(playerid, a);
    new Float:newx = x + (distance * floatsin(-a, degrees));
    new Float:newy = y + (distance * floatcos(-a, degrees));
    //We now have the distance in front of the player.
    SetPlayerCameraPos(playerid, newx, newy, z); //Set the camera behind or in front of the player. ('distance'... Behind = Negative, In front = Positive)
    x = newx, y = newy;
    a -= 90.0;
    newx += floatmul(floatsin(-a, degrees), offset);
    newy += floatmul(floatcos(-a, degrees), offset);
    InterpolateCameraPos(playerid, x, y, z, newx, newy, z, 2000, CAMERA_MOVE); //Move the camera to beside the player. ('offset'... Left = Negative, Right = Positive)
    return 1;
}
Basically, distance is the distance from the player. A positive distance means in front of the player. A negative distance means behind the player.
For example: SetCameraNextToPlayer(playerid, 2, ...) will set the camera in front of the player. SetCameraNextToPlayer(playerid, -2, ...) will set the camera behind the player.
'offset' works in the same way. This is the distance of how far away you want the camera from the player in terms of the 'sideways' length.
For example: SetCameraNextToPlayer(playerid, ..., 2) will set the camera to the right of the player. SetCameraNextToPlayer(playerid, ..., -2) will set the camera to the left of the player.

--
This command is an example of how you would use it:
pawn Код:
CMD:setcamera(playerid, params[])
{
    new Float:distance, Float:offset;
    if(sscanf(params, "ff", distance, offset)) return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /setcamera [distance] [offset]");
    SetCameraNextToPlayer(playerid, distance, offset);
    return 1;
}
Reply


Messages In This Thread
Set camera next to player - by Riddick94 - 26.12.2013, 13:33
Re: Move camera next to the player - by J4mmyHD - 26.12.2013, 18:12
Re: Move camera next to the player - by Riddick94 - 26.12.2013, 18:29
Respuesta: Move camera next to the player - by [DOG]irinel1996 - 26.12.2013, 18:31
Re: Respuesta: Move camera next to the player - by Riddick94 - 26.12.2013, 18:43
Re: Move camera next to the player - by Threshold - 27.12.2013, 04:50
Re: Move camera next to the player - by Riddick94 - 27.12.2013, 15:22

Forum Jump:


Users browsing this thread: 3 Guest(s)