0

我正在开发一款横向卷轴 2D 平台游戏,我有一段时间在背景中有一个焦点,我想向玩家展示一个“aw”的时刻,我想将相机缩小到显示那一刻,然后再次放大。我想当他们想要显示的对象对于相机的尺寸来说太大时,你可以说像 Death's Gambit 或空心骑士一样做同样的事情。

试图从某个区域的玩家获得变换并计算到我希望相机尺寸达到最大值的点的距离,然后计算其中的一个百分比以添加乘以尺寸差异,但它会破坏查看端口使其变得清晰或缩小到允许的最大单位。

预期的结果是让相机缩小到世界上某个点的距离,经过那个点它会停止缩小,向后退应该放大到具有初始 OrtographicSize 的玩家。

感谢您的帮助!

4

1 回答 1

0

你可以做:

public Transform Target1;
public Transform Target2;

public float sensetivity = 1f;
public float maxOrthographicSize = 10f;

Camera thisCam;
float minOrthographicSize = 5f;

private void Start() {
    thisCam = GetComponent<Camera>();
    minOrthographicSize = thisCam.orthographicSize;
}
void Update()
{
    thisCam.orthographicSize = minOrthographicSize + Mathf.Clamp(Vector2.Distance(Target1.position, Target2.position) * sensetivity, 0f, maxOrthographicSize);
}

在此解决方案minOrthographicSize中,只有在Target1并且Target2处于相同位置时才会发生,以改变您可以执行的操作:

public Transform Target1;
public Transform Target2;

public float minOrhtographicDistance = 5f;
public float sensetivity = 1f;
public float maxOrthographicSize = 10f;

Camera thisCam;
float min = 5f;

private void Start() {
    thisCam = GetComponent<Camera>();
    min = thisCam.orthographicSize;
}
void Update()
{
    thisCam.orthographicSize = min + Mathf.Clamp((Vector2.Distance(Target1.position, Target2.position) - minOrhtographicDistance) * sensetivity, 0f, maxOrthographicSize);
}

在此解决方案中,正交尺寸将minOrthographicSize用于minOrhtographicDistance距离,然后会根据目标之间的距离而变化。

于 2019-06-13T11:38:52.113 回答