Tuesday, July 1, 2025
spot_img

Digicam Snapping as an alternative of panning


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

Observe, usually following the participant

Horizontal: Y is ready, X follows participant

Static: Locked to a sure place on the earth

After I swap between modes, the digital camera snaps to the brand new location instantly. I need it to pan as seen in 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] non-public Remodel playerTransform;

    [Header("Flip Rotation Stats")]
    [SerializeField] non-public float flipVRotationTime = 0.5f;

    non-public Participant participant;

    non-public bool isFacingRight;

    non-public void Begin()
    {
        rework.place = participant.rework.place;
        enabled = true;
        participant = playerTransform.gameObject.GetComponent<Participant>();
        isFacingRight = participant.motor.facingRight;
    }

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

        rework.place = goal;
    }

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

    non-public float DetermineEndRotation()
    {
        isFacingRight = !isFacingRight;

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

Digicam Observe Object follows the participant and rotates on participant flip to easily pan from left bias to proper bias.

utilizing System.Collections;
utilizing UnityEngine;
utilizing Cinemachine;

public class CameraManager : MonoBehaviour
{
    public static CameraManager occasion;
    non-public CamMode currentMode;
    [SerializeField] non-public CameraFollowObject followObject;

    public bool isLerpingYDamping { get; non-public set; }
    public bool lerpedFromPlayerFalling { get; set; }

    non-public 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;
        }
    }
}

Digicam Supervisor to modify Cameras

The Cameras are switched by triggers, all of it works completely high quality, solely factor is, that the digital camera immediately snaps. I attempted altering the rework.place = goal; to lerp between present and goal, however that simply made the digital camera fall behind when strolling.

Framing Transposer Setings:
d

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles