我正在制作一款游戏,它有多达4个正交摄像机(最多4个玩家),根据玩家的数量占据不同数量的屏幕.


我有一个控制所有摄像机的脚本,设置相对于他们正在观看的玩家的位置.
我想要实现的是一种简单的头顶跑步运动风格,摄像机将跟随玩家,但不会超出地图范围.

当相机处于"方形"时(如在4人布局中),我已设法在左上角的相机中工作.但是,其他相机根本没有正确跟踪,而在矩形双人模式下,顶部相机仍然左右移动太远.我很确定我确切地知道哪一行代码导致问题...但我不知道我需要做些什么来解决它...
SpriteRenderer spriteBounds = GameObject.Find("Map").GetComponentInChildren<SpriteRenderer>();
float leftBound =0;
float rightBound =0;
float bottomBound =0;
float topBound = 0;
if((trackPlayer1 == null))
{
camPlayer1.transform.position = this.transform.position;
}
else
{
float vertExtent = camPlayer1.orthographicSize;
float horzExtent = vertExtent * Screen.width / Screen.height; //I guess the problem is here... but how do I fix this??
leftBound = (float)(horzExtent - spriteBounds.sprite.bounds.size.x / 2.0f);
rightBound = (float)(spriteBounds.sprite.bounds.size.x / 2.0f - horzExtent);
bottomBound = (float)(vertExtent - spriteBounds.sprite.bounds.size.y / 2.0f);
topBound = (float)(spriteBounds.sprite.bounds.size.y / …Run Code Online (Sandbox Code Playgroud)