27.12.2013, 04:50
This is a code I have just quickly whipped up:
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 Код:
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;
}
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;
}