Talking about the development of the game in all kinds of games third-person camera to achieve

        Blink of an eye, at the end of the Mini project Netease, finally have time to write something, a look at the time, but also had more months without good blog, and in retrospect, the past few months in fact, unlike what kind of year things did not really learn something written by the state, but certainly do Mini project a little too busy, taking advantage of the completion of the project during this time, and quickly write something, because when doing the Mini project related to the character and camera control operations are I do, and the camera perspective of the game in the third person, in the development process can be considered in this regard with a deeper understanding of what the so Xiaobian today classify all kinds of games in camera and implementation.

        In fact, the camera is essentially the eyes of the player, the player in the game can see all cameras in the game scene saw. First, let's analyze the perspective of the game, during the game when it comes to viewing angle, in general, we can be divided into first-person perspective and third-person, in addition, may also have the perspective of some of the non-player controlled, For example cutscenes. When it comes to first-person perspective game, the first time so that we could think of shooting games, shooting games are based on the most first-person perspective, of course, there are games TPS (Third Person Shooter), such as the Jedi will have to survive TPP mode, but since most shooters have emphasized a fair shot horizons, while the target is within the field of view, within its field of vision is also a target, so the majority of the first-person perspective shooting games are used. In the first-person game, since the field of view and the character is facing almost bound, so the camera can be bound to the skeleton model of the character, the character controlled by the rotation direction while the camera is rotated. But this simple and crude way can not be used in third-person mode, because in the third-person perspective, the camera's orientation is no longer one hundred percent of a person's direction and, of course, this is also a special case can be divided the same can survive by Jedi to, for example, in the Jedi survival TPP mode, when we hold the right conduct waist shot, our characters towards is almost and camera towards the same, if we do the game is we need to have Keep the camera and characters the same direction, we can also bind directly to the camera in the character bones. Similar to the Devil May Cry, the game most of the third-person camera is turning around our characters, but not towards the binding character orientation, but the player can rotate the camera by yourself operation, and we moved when moving characters direction is the direction of our camera according to the decision, so in such conditions, we can not bind the camera on the character model, in which case we will need three key parameters to control the position of the camera: camera 1 2. the camera viewpoint toward the camera 3 and the observation point distance.

        First small series camera to explain this observation point, when if we play this kind of game in the third person, we put the camera in position to move it forward, you will find some games after the forward camera is not necessarily aligned figures after the center, then this point, we call the viewpoint of the camera, this observation point we can bind the character models, because it is ready to follow the movement of the characters to update location, with this viewpoint, we You can determine the location and orientation of the camera by camera from the camera, based on these three parameters, our cameras will be able to ensure its implementation has been essentially turn around the player.

if (Target != null)
{
    //print(CrossPlatformInputManager.GetAxis("Mouse X") + " " + CrossPlatformInputManager.GetAxis("Mouse Y"));
    mX += CrossPlatformInputManager.GetAxis("Mouse X") * SpeedX * 0.1f;
    mY += -CrossPlatformInputManager.GetAxis("Mouse Y") * SpeedY * 0.1f;
    mY = ClampAngle(mY, MinLimitY, MaxLimitY);
    mRotation = Quaternion.Euler(mY, mX, 0);
    if (isNeedDamping)
    {
        transform.rotation = Quaternion.Lerp(transform.rotation, mRotation.normalized, Time.deltaTime * Damping);
    }
    else
    {
        transform.rotation = mRotation;
    }
}
d = Distance;
RaycastHit hit;
int layerMask = ~(1 << 12);
if (Physics.SphereCast(Target.position, 0.2f, -transform.forward, out hit, Distance, layerMask))
{
    //print(hit.collider.name);
    GameObject hitG = hit.collider.gameObject;
    AIControl AI = hitG.GetComponent<AIControl>();
    Door door = hitG.GetComponent<Door>();
    DoorCollider doorCollider = hitG.GetComponent<DoorCollider>();
    if (AI == null && door == null && doorCollider == null)
    {
        d = Mathf.Clamp(hit.distance, 0.0f, Distance);
    }

}
if (d < 1.0f)
{
    player_mesh.SetActive(false);
}
else
{
    player_mesh.SetActive(true);
}
Vector3 mPosition = mRotation * new Vector3(0, 0, -d) + Target.position;
if (isNeedDamping)
{
    transform.position = Vector3.Lerp(transform.position, mPosition, Time.deltaTime * Damping);
}
else
{
    transform.position = mPosition;
}

 

Guess you like

Origin blog.csdn.net/RaAlGhul/article/details/93519891