浏览代码

Add Smoothing to CameraFollow script (#4422)

* update cam script & add comments

* use fixedDeltaTime in SmoothDamp
/MLA-1734-demo-provider
GitHub 4 年前
当前提交
fc46ff58
共有 1 个文件被更改,包括 12 次插入6 次删除
  1. 18
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/CameraFollow.cs

18
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/CameraFollow.cs


{
public class CameraFollow : MonoBehaviour
{
public Transform target;
Vector3 m_Offset;
[Tooltip("The target to follow")] public Transform target;
[Tooltip("The time it takes to move to the new position")]
public float smoothingTime; //The time it takes to move to the new position
private Vector3 m_Offset;
private Vector3 m_CamVelocity; //Camera's velocity (used by SmoothDamp)
// Use this for initialization
void Start()

// Update is called once per frame
void Update()
void FixedUpdate()
// gameObject.transform.position = target.position + offset;
gameObject.transform.position = newPosition;
gameObject.transform.position =
Vector3.SmoothDamp(transform.position, newPosition, ref m_CamVelocity, smoothingTime, Mathf.Infinity,
Time.fixedDeltaTime);
}
}
}
正在加载...
取消
保存