Sunday, November 13, 2022
HomeGame Developmentunity - Digicam observe participant with Lerp and transferring away after idle

unity – Digicam observe participant with Lerp and transferring away after idle


So I am making a clone of Crossy Roads the place the digital camera follows the participant. It does some linear interpolation (Lerp) after transferring, and the digital camera begins transferring away from the participant within the optimistic route (x-axis till digital camera reaches to a sure vary the place participant will not be seen sufficient). Issues I’ve tried is by flagging it, however I believe I am doing it incorrect.

I’ve finished my digital camera actions accordingly, however I’m having a problem the place the situations should not correctly met. I am get the offset digital camera after not transferring, but it surely doesn’t the Lerp, and vice-versa. I would like each to occur after a sure situation after the sport begins. When the participant strikes, the digital camera follows it in Lerp. Nonetheless, as soon as the participant is “Idle”, its nonetheless Lerping. I would like the digital camera to proceed by itself and on the similar time focus on the participant’s object.

utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;

/*
** Digicam following participant (Smoothing and angle): https://youtu.be/4HpC--2iowE
** Maximo: https://www.youtube.com/watch?v=bXNFxQpp2qk&ab_channel=iHeartGameDev
** Shifting character relative to digital camera: https://discussion board.unity.com/threads/moving-character-relative-to-camera.383086/
** Digicam observe v2: https://youtu.be/Jpqt2gRHXtc?checklist=PLq_nO-RwB516fNlRBce0GbtJSfysAjOgU
*/

public class CameraController : MonoBehaviour
{
    public GameObject participant;
    public PlayerControl playerControlScript;
    personal Vector3 newCameraPos;
    public bool stillIdle;

    void Begin()
    {
        stillIdle = false; 
        PlayerControl playerControlScript = GetComponent<PlayerControl>();
    }

    void LateUpdate()
    {
        participant = GameObject.FindGameObjectWithTag("Participant");
        if (playerControlScript.GetfirstInput()) //True
        {
            stillIdle = true;
            newCameraPos = Vector3.Lerp(rework.place, playerControlScript.rework.place, Time.deltaTime);
            rework.place = new Vector3(newCameraPos.x, 1, newCameraPos.z);
        }
        if (stillIdle)
            rework.place = new Vector3(rework.place.x + 0.69f * Time.deltaTime, rework.place.y, rework.place.z); //Shifting digital camera away impact
    }
}

Some assist could be admire it. I really feel I’ve been looking at this downside and I wager it’s one thing minimal and small from simply pondering it.

Let me know for those who want clarifications. I am pleased to edit and reply them for everybody

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments