1

我正在使用 Unity 3,我的总关卡大小将只是一个四边形区域,每边都有一堵墙。其中将有两堵额外的墙,形成一个围墙,将玩家限制在逐渐扩展的关卡的一部分。

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

我知道Vector3.lerp可能会有所帮助,但我正沉浸在变换和不同的比例中,因此希望能得到帮助。

4

1 回答 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);
于 2011-03-16T11:21:38.640 回答