Unity3d 团结:停止摄影机跟随玩家?
我正在学习《生存射手统一》教程,在该教程中,给定的代码用于使相机跟随玩家。该代码正在工作,但我如何修改它,使其在给定的X和Y点停止跟随玩家 代码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
只要停止更新他的职位:
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;
...