24.5 C
New York
Wednesday, July 2, 2025

Chamber Snapping as a substitute of panoramic


I’m making an attempt to make a digital camera system for a 2D platform sport, with three digital camera modes to start out:

Comply with, usually following the participant

Horizontal: y is configured, x follows the participant

Static: blocked to a sure place of the world

After I change between methods, the digital camera suits the brand new location instantly. I need you to take a look at video games like Hole Knight.

That is my code:

utilizing UnityEngine;

public class CameraFollowObject : MonoBehaviour
{
    public CamMode mode { get; set; }
    public Vector2 place { get; set; }

    (Header("References"))
    (SerializeField) personal Remodel playerTransform;

    (Header("Flip Rotation Stats"))
    (SerializeField) personal float flipVRotationTime = 0.5f;

    personal Participant participant;

    personal bool isFacingRight;

    personal void Begin()
    {
        remodel.place = participant.remodel.place;
        enabled = true;
        participant = playerTransform.gameObject.GetComponent<Participant>();
        isFacingRight = participant.motor.facingRight;
    }

    public void UpdateCamera()
    {
        Vector2 goal = mode swap
        {
            CamMode.Horizontal => new Vector2(participant.remodel.place.x, place.y),
            CamMode.Static => place,
            _ => participant.remodel.place
        };

        remodel.place = goal;
    }

    public void CallTurn()
    {
        LeanTween.rotateY(gameObject, DetermineEndRotation(), flipVRotationTime).setEaseInOutSine();
    }

    personal float DetermineEndRotation()
    {
        isFacingRight = !isFacingRight;

        if (isFacingRight)
        {
            return 0f;
        }
        else
        {
            return 180f;
        }
    }
}

The digital camera monitoring object follows the participant and turns within the turned participant to maneuver gently from the left bias to the proper bias.

utilizing System.Collections;
utilizing UnityEngine;
utilizing Cinemachine;

public class CameraManager : MonoBehaviour
{
    public static CameraManager occasion;
    personal CamMode currentMode;
    (SerializeField) personal CameraFollowObject followObject;

    public bool isLerpingYDamping { get; personal set; }
    public bool lerpedFromPlayerFalling { get; set; }

    personal void Awake()
    {
        if (occasion == null)
        {
            occasion = this;
        }
    }

    public void SwapCamera(CamMode left, CamMode proper, Vector2 exitDir, Vector2 pos)
    {
        if (currentMode == left && exitDir.x > 0f)
        {
            followObject.place = pos;
            currentMode = followObject.mode = proper;
            return;
        }

        if (currentMode == proper && exitDir.x < 0f)
        {
            followObject.place = pos;
            currentMode = followObject.mode = left;
            return;
        }
    }
}

Digital camera supervisor to alter cameras

The cameras are modified by triggers, every little thing works completely properly, the one factor is that the digital camera immediately breaks. I attempted to alter the remodel. Place = goal; Lerp between the present and the target, however that has simply made the digital camera be left behind when strolling.

Transposer configurations framed:

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles