- Home /
Enable the OrbitCam script how can I make it will continue from the current camera view and position ?
The game start when the main camera is at one position then the camera move to a new position when the camera finished moving I'm enabling another script :
This is a screenshot showing the camera position after it finished moving :
Inside the LateUpdate I'm enabling the OrbitCam script :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class PlayingInGameScenesController : MonoBehaviour
{
public GameObject camera;
public LockController lockController;
public GameObject uiTextsImage;
public float transitionSpeed = 5f;
public Transform currentView;
public float thresHold = 0.1f;
// The initial offset from the target.
private Vector3 offset;
private bool newGame = true;
private bool playingScene = true;
private Vector3 newPos;
private void Start()
{
currentView.position = new Vector3(43.4f, 1f,-6f);
offset = camera.transform.position - currentView.position;
}
public void PlayingSceneInGame()
{
PlayingSceneStatesControls(true);
StartCoroutine(ScenePlayingTime());
}
private void Update()
{
if (SceneManager.GetActiveScene().name != "Main Menu" && newGame == true)
{
PlayingSceneInGame();
newGame = false;
}
}
private void LateUpdate()
{
if (playingScene == false)
{
//Lerp position
camera.transform.position = Vector3.Lerp(camera.transform.position, currentView.position, Time.deltaTime * transitionSpeed);
if (Vector3.Distance(camera.transform.position, currentView.position) < thresHold)
{
camera.GetComponent<OrbitCam>().enabled = true;
}
}
}
private void PlayingSceneStatesControls(bool LockState)
{
lockController.LockControl(LockState);
if (LockState == true)
{
uiTextsImage.SetActive(true);
}
else
{
uiTextsImage.SetActive(false);
playingScene = false;
}
}
IEnumerator ScenePlayingTime()
{
yield return new WaitForSeconds(10);
PlayingSceneStatesControls(false);
}
}
The problem is when it's enabling the OrbitCam script the OrbitCam script change the camera view and position and I want that the game will continue from the current camera view and position. I want to be able to use the orbitcam script it's working fine but to start using it from the last camera position and view as in the first screenshot.
When the OrbitCam script enabled it's changing the view and position of the camera to this :
I want that when the OrbitCam script is enable true first time don't change the camera view and position just start using the oribtcam script from the current camera view and position like in the first screenshot that should be the start point of using the OrbitCam script.
Your answer
Follow this Question
Related Questions
Free camera look question 2 Answers
How to make my Camera Controller look at target 0 Answers
Unity Editor Like Camera Script? 1 Answer
Having Trouble animating camera at start of game 0 Answers
Handling Cinemachine Freelook Camera with Touch Input to pan 0 Answers