Download Report Appendices
Transcript
/// /// <summary>
/// The target rotation - the new quaternion to rotate toward.
/// </summary>
private Quaternion targetRotation;
/// <summary>
/// Start this instance.
/// set inst to this gameobject instance
/// </summary>
void Start ()
{
inst = this;
}
/// <summary>
/// Update this instance.
/// set new target vector for rotation
/// rotate to target
/// apply to instance
/// </summary>
void Update ()
{
targetPoint = new Vector3(target.transform.position.x, transform.position.y,
target.transform.position.z) - transform.position;
targetRotation = Quaternion.LookRotation (-targetPoint, Vector3.up);
inst.gameObject.transform.rotation = Quaternion.Slerp(transform.rotation,
targetRotation, 0.1f);
FlightCoordinator.cs
/* Adapted from a Sam Cox JavaScript - 2009 - FrictionPointStudios.com
* C# conversion, documentation and optimization by G.Wright 2013
* - Final adapted Code utilises LookRotation instead of the heavy LookAt() Unity
Engine method
*/
using UnityEngine;
using System.Collections;
/// <summary>
/// Flight coordinator.
/// </summary>
public class FlightCoordinator: MonoBehaviour
{
//array instance of waypoint
private FlyToNextWaypoint[] waypoints;
/// <summary>
/// current bezier cache
/// </summary>
private WaypointBezier bezier;
/// <summary>
/// The current waypoint in flyNextWaypoints array
/// </summary>
int currentWaypoint = 0;
/// <summary>
/// The seconds for full loop.
/// Holds a time value to complete a full loop by
/// </summary>
public float SecondsForFullLoop = 60f;
/// <summary>
/// The target point.
/// </summary>
private Vector3 targetPoint;
/// <summary>
/// The target rotation.
/// vector to cache to the targets axis of rotation