如何在Unity中的两个Z轴点之间进行翻转,并相应地缩放组件

问题描述 投票:1回答:1

我正在使用Unity 3,我的总体尺寸将只是一个四边形区域,每边都有一面墙。在这将是两个额外的墙壁,创建一个外壳,将玩家限制在逐渐扩展的水平的一部分。

我将这两个墙称为ZBoundary和XBoundary,到目前为止,原型已将其运动映射到某些键盘键。我想要做的是当一个移动时,另一个移动长度因此它们总是以垂直角度连接,所以我希望能够在例如ZBoundary的Z坐标和Z坐标之间进行线性插值。 Xboundary,以便它们始终相遇并创建连接。这也会产生问题,因为我不知道如何以编程方式更改GameComponent的大小,并且不断出错。

我知道Vector3.lerp可能有所帮助,但我淹没在变形和不同的尺度,所以会很感激帮助。

c# unity3d scale interpolation
1个回答
0
投票

我已经到了一半,现在让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);
© www.soinside.com 2019 - 2024. All rights reserved.