سؤال

I'm working with Unity 3 and my total level size will be just a quadrilateral area with a wall on each side. Within this will be two additional walls that create an enclosure that restricts the player to a portion of the level that gradually expands.

I call these two walls ZBoundary and XBoundary, and so far for a prototype have mapped their movement to some keyboard keys. What I want to do is when one moves, the other grows in length so they are always joined at a perpendicular angle, so I want to be able to linearly interpolate between, for example, the ZBoundary's Z-coordinate and the Z-coordinate of the Xboundary so that they always meet and create a join. This creates a problem as well, because I don't know how to change the size of a GameComponent programmatically, and keep getting errors.

I know Vector3.lerp may help but I'm drowning in transforms and different scales and so would appreciate the help.

هل كانت مفيدة؟

المحلول

I'm halfway there by now getting the XBoundary to adjust its position in order to always lock to the ZBoundary at 90degrees

        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);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top