如何在Unity中以2个Z轴点点进行LERP,并相应地扩展组件
-
25-10-2019 - |
题
我正在使用Unity 3工作,我的总水平大小将只是四边形区域,每侧都有墙壁。在此中将是两个额外的墙壁,这些墙壁创建一个围墙,将玩家限制在逐渐扩展的水平的一部分。
我称这两堵墙为Zboundary和Xboundary,到目前为止,原型已将其移动映射到了一些键盘键。我要做的是当一个移动时,另一个移动的长度会始终以垂直角度连接,因此我希望能够在例如Zboundary的Z坐标和Z坐标之间线性插值Xboundary,以便他们总是见面并创建一个联接。这也会产生一个问题,因为我不知道如何以编程方式更改游戏机的大小并继续遇到错误。
我知道 Vector3.lerp
可能会有所帮助,但我淹没了转型和不同的量表,因此会感谢您的帮助。
解决方案
我现在已经到了一半,到了xboundary来调整其位置,以便始终锁定90度的Zboundary
ZBoundaryRef.transform.Translate((-1 * distancePerZMovement), 0, 0, Space.World);
// using Space.World so transforms are using the global coordinate system!
// what I've done here is say, move the XBoundary Z-CoOrd so that it aligns with the ZBoundary Z-CoOrd.
// the origin of an object is at it's centre point so we need to take this in to account to ensure they join at the corners, not in a Tshape!
float difference = (ZBoundaryRef.transform.position.x - XBoundaryRef.transform.position.x);
float adjustment = difference + (ZBoundaryRef.transform.localScale.x/2);
XBoundaryRef.transform.Translate(adjustment,0,0,Space.World);
不隶属于 StackOverflow