Monday, July 11, 2022
HomeGame Developmentunity - How you can hold a digicam confined inside a 3d...

unity – How you can hold a digicam confined inside a 3d Collider


I’m making an attempt to create a confiner for my digicam utilizing the bounds of a collider, the problem is that once I hit the wall of the confiner, I must disable the digicam motion, however since I disable it, I now can’t transfer it in any respect.

I’ve tried all I can consider like storing the final “legitimate” place and restoring it if confiner is hit, however that doesn’t appear to work.

void HandleInput()
    {
        if (inputDisabled)
            return;

        //Pace controls
        if (Enter.GetKey(KeyCode.LeftShift))
        {
            movementSpeed = fastSpeed;
        }
        else
        {
            movementSpeed = normalSpeed;
        }

        // Modify motion pace based mostly on digicam zoom
        movementSpeed *= (cameraTransform.localPosition.y / zoomSpeedFactor);

        Vector3 adjustedForward = rework.ahead;
        adjustedForward.y = 0;

        //Motion controls
        if (Enter.GetKey(KeyCode.W) || Enter.GetKey(KeyCode.UpArrow))
        {
            newPosition += (adjustedForward * movementSpeed);
        }
        if (Enter.GetKey(KeyCode.S) || Enter.GetKey(KeyCode.DownArrow))
        {
            newPosition += (adjustedForward * -movementSpeed);
        }
        if (Enter.GetKey(KeyCode.D) || Enter.GetKey(KeyCode.RightArrow))
        {
            newPosition += (rework.proper * movementSpeed);
        }
        if (Enter.GetKey(KeyCode.A) || Enter.GetKey(KeyCode.LeftArrow))
        {
            newPosition += (rework.proper * -movementSpeed);
        }

        //Zoom controls
        if (Enter.mouseScrollDelta.y != 0 && !EventSystem.present.IsPointerOverGameObject())
        {
            newZoom -= Enter.mouseScrollDelta.y * zoomAmount;
            newZoom.y = ClampValue(newZoom.y, zoomClamp.x, zoomClamp.y);
        }

        if (!collider.bounds.Comprises(newPos)) //DISABLE MOVEMENT
            return;

        rework.place = Vector3.Lerp(rework.place, newPosition, Time.unscaledDeltaTime * acceleration);
        cameraTransform.localPosition = Vector3.Lerp(cameraTransform.localPosition, newZoom, Time.unscaledDeltaTime * acceleration);
    }

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments