using System.Collections; using System.Collections.Generic; using UnityEngine; ///…
- User
using System.Collections; using System.Collections.Generic; using UnityEngine;
/// /// Causes the camera to try to move to camPoint and LookAt lookPoint, which are /// both empty GameObject children of Plane. /// [DisallowMultipleComponent] public class ChaseCam : MonoBehaviour { [Header("Inscribed")] public Transform camPoint; public Transform lookPoint; public float easing = 0.15f;
void FixedUpdate() { // Call Follow() every FixedUpdate(). // This happens in FixedUpdate rather than Update so that the Camera // moves in synchronization with the movement of the plane. } void Follow() { // We want the camera position to move toward the CamPoint child of // Plane and look at the LookPoint child of Plane // Set transform.position based on a Zeno's Paradox version of linear // interpolation with easing as the U value. Look up Zeno's Paradox // in Appendix B or look at how the camera moved in Mission Demolition // Use transform.LookAt to make the Camera look at lookPoint.position } /// <summary> /// You can use this to call Follow() while working in the Editor. It doesn't /// always work perfectly, because the Editor doesn't draw gizmos every /// frame when you're not playing, but it is still helpful to automatically /// position the Camera. /// </summary> private void OnDrawGizmos() { // I've written this method for you; you don't need to add anything. if (camPoint == null || lookPoint == null) return; if (!Application.isPlaying) { Follow(); } }} Fill out the code for the comments listed under the FixedUpdate() function
- Assistant
// Call Follow() every FixedUpdate(). Follow();
- User
using System.Collections; using System.Collections.Generic; using UnityEngine;
/// /// Causes the camera to try to move to camPoint and LookAt lookPoint, which are /// both empty GameObject children of Plane. /// [DisallowMultipleComponent] public class ChaseCam : MonoBehaviour { [Header("Inscribed")] public Transform camPoint; public Transform lookPoint; public float easing = 0.15f;
void FixedUpdate() { // Call Follow() every FixedUpdate(). Follow(); // This happens in FixedUpdate rather than Update so that the Camera // moves in synchronization with the movement of the plane. } void Follow() { // We want the camera position to move toward the CamPoint child of // Plane and look at the LookPoint child of Plane // Set transform.position based on a Zeno's Paradox version of linear // interpolation with easing as the U value. Look up Zeno's Paradox // in Appendix B or look at how the camera moved in Mission Demolition // Use transform.LookAt to make the Camera look at lookPoint.position } /// <summary> /// You can use this to call Follow() while working in the Editor. It doesn't /// always work perfectly, because the Editor doesn't draw gizmos every /// frame when you're not playing, but it is still helpful to automatically /// position the Camera. /// </summary> private void OnDrawGizmos() { // I've written this method for you; you don't need to add anything. if (camPoint == null || lookPoint == null) return; if (!Application.isPlaying) { Follow(); } } - Assistant
void Follow() { // Calculate the desired position by interpolating the current camera position and the camPoint position using easing value. // You can use Mathf.Lerp() function to perform the interpolation. Vector3 desiredPosition = Vector3.Lerp(transform.position, camPoint.position, easing);
// Set the camera position to the desired position. transform.position = desiredPosition; // Use transform.LookAt to make the camera look at lookPoint position. transform.LookAt(lookPoint);}