- Home /
Moving FPSCamera to fixed positions during OnClick of objects
What I've done so far: I am making a virtual tour through a mesh. I developed a model for when the FPS (Standard Asset Prefab) clicks on objects in the tour, a camera switch occurs and the user can view a point-of-interest from an ideal angle while reading about it (Canvas attached).
Problem: The camera switch occurs too quickly to give the user any spatial knowledge during the tour. Goal: I would like the FPS camera to move to a new position that I have specified with an empty object providing the coordinates. So far, my code is accepted by unity and I can run my game, but the camera transition does not seem to occur. Ultimately, I will need the camera to return to the FPSController on command (button on canvas). I'm wondering if the bond between the FPSController and Camera is "unbreakable." Thanks in advance for your guidance. Here is the code I'm using currently:
(code modified from youTube User, Black Box) public class CameraSwitcherSmooth : MonoBehaviour {
public static int camSelect;
public Transform[] views;
public float transitionSpeed;
Transform currentView;
// Define cameras and canvases
public Canvas canSyncline;
// Use this for initialization
void Start()
{
camSelect = 0;
}
void Update()
{
if (camSelect == 0)
{
currentView = views[0];
canSyncline.enabled = false;
}
else if (camSelect == 1)
{
currentView = views[1];
canSyncline.enabled = true;
}
}
void LateUpdate()
{
//Lerp position
transform.position = Vector3.Lerp(transform.position, currentView.position, Time.deltaTime * transitionSpeed);
Vector3 currentAngle = new Vector3(
Mathf.LerpAngle(transform.rotation.eulerAngles.x, currentView.transform.rotation.eulerAngles.x, Time.deltaTime * transitionSpeed),
Mathf.LerpAngle(transform.rotation.eulerAngles.y, currentView.transform.rotation.eulerAngles.y, Time.deltaTime * transitionSpeed),
Mathf.LerpAngle(transform.rotation.eulerAngles.z, currentView.transform.rotation.eulerAngles.z, Time.deltaTime * transitionSpeed));
transform.eulerAngles = currentAngle;
}
}