Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unity3d 团结:停止摄影机跟随玩家?_Unity3d_Camera - Fatal编程技术网

Unity3d 团结:停止摄影机跟随玩家?

Unity3d 团结:停止摄影机跟随玩家?,unity3d,camera,Unity3d,Camera,我正在学习《生存射手统一》教程,在该教程中,给定的代码用于使相机跟随玩家。该代码正在工作,但我如何修改它,使其在给定的X和Y点停止跟随玩家 代码 只要停止更新他的职位: private bool followPlayer = true; void FixedUpdate () { if(followPlayer){ // Create a postion the camera is aiming for based on the offset from the targe

我正在学习《生存射手统一》教程,在该教程中,给定的代码用于使相机跟随玩家。该代码正在工作,但我如何修改它,使其在给定的X和Y点停止跟随玩家

代码


只要停止更新他的职位:

private bool followPlayer = true;
void FixedUpdate ()
{
    if(followPlayer){
        // Create a postion the camera is aiming for based on the offset from the target.
        Vector3 targetCamPos = target.position + offset;

        // Smoothly interpolate between the camera's current position and it's target position.
        transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);
    }
}

将followPlayer的值更改为false,它将停止跟踪

只需停止更新其位置:

private bool followPlayer = true;
void FixedUpdate ()
{
    if(followPlayer){
        // Create a postion the camera is aiming for based on the offset from the target.
        Vector3 targetCamPos = target.position + offset;

        // Smoothly interpolate between the camera's current position and it's target position.
        transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);
    }
}

将followPlayer的值更改为false,它将停止跟随

以确定玩家是否在给定点,您需要检查玩家与该点之间的距离,例如:

public Transform target;                // player position
public Transform stopingPoint;          // stopping point position
public double tolerance;                // the "radius" of stopping point

private bool followPlayer = true;

    ...

void FixedUpdate ()
{
    if(!followPlayer)
        return;
    followPlayer = Vector3.Distance(target.position, stopingPoint.position) <= tolerance;

    ...

要确定玩家是否在给定点,您需要检查玩家与该点之间的距离,例如:

public Transform target;                // player position
public Transform stopingPoint;          // stopping point position
public double tolerance;                // the "radius" of stopping point

private bool followPlayer = true;

    ...

void FixedUpdate ()
{
    if(!followPlayer)
        return;
    followPlayer = Vector3.Distance(target.position, stopingPoint.position) <= tolerance;

    ...