Just because StarFox (or StarWing as it’s called here) practically raised me.
I think I would have set up trigger areas for this and let the player have a constant force forward towards them. The trigger areas would serve as waypoints and the player always looks at the next oncoming waypoint (preferably an empty gameobject which looks at the waypoints and the player model that interpolates between that and the actual player input position with limitations to angles and positions according to the next waypoint).
You’d have to come up with the logic around it according to how you want the game to act out, but just to get you started here’s a little bit of code:
//This script (referenced as playerScript in the code) would be on the parent to the player
//Put your waypoints inside an empty gameobject and name them waypoint1 - (quantity)
var player : Transform; //The player model
var cam : Camera; //Player camera
var waypointsParent : Transform; //Parent of all waypoints
var speed : float = 5.0; //Speed of sideways movement
var flightSpeed : float = 10; //Speed of forward movement
var rotationSpeed : float = 4; //Speed of smooth look towards target
static var waypointQuantity : int; //How many waypoints
static var nextWaypoint : Transform; //The current waypoint to reach
static var playerCurrentWaypoint : int = 1; //The current waypoint to reach in number
static var nextLevel : int = 2; // For future use perhaps
function Start() {
nextWaypoint = GameObject.Find("waypoint1").transform;
waypointQuantity = waypointsParent.childCount;
}
//Move the localPosition of the player model
function Update() {
var screenPos : Vector3 = cam.WorldToScreenPoint(player.transform.position);
if(Input.GetAxis("Horizontal")<0 && screenPos.x>0) player.localPosition.x-=speed*Time.deltaTime;
if(Input.GetAxis("Horizontal")>0 && screenPos.x<Screen.width) player.localPosition.x+=speed*Time.deltaTime;
if(Input.GetAxis("Vertical")<0 && screenPos.y>0) player.localPosition.y-=speed*Time.deltaTime;
if(Input.GetAxis("Vertical")>0 && screenPos.y<Screen.height) player.localPosition.y+=speed*Time.deltaTime;
//Move the entire player area
transform.Translate(Vector3.forward * flightSpeed * Time.deltaTime);
var targetPoint = nextWaypoint.position;
var targetRotation = Quaternion.LookRotation(nextWaypoint.position - player.transform.position, Vector3.up);
transform.rotation = Quaternion.Slerp(player.transform.rotation, targetRotation, Time.deltaTime * rotationSpeed);
}
As for the waypoints:
//This script would be on each of the waypoints which can be just a collider that is set to trigger
function OnTriggerEnter (other : Collider) {
if(other.tag!="Player")return;
//Check if there are waypoints left otherwise this level is done (just as an example)
if(playerScript.playerCurrentWaypoint<playerScript.waypointQuantity){
playerScript.playerCurrentWaypoint++;
}else{
//Application.loadLevel("level"+playerScript.nextLevel.ToString());
}
//Set the next waypoint for the player to look at
playerScript.nextWaypoint = GameObject.Find("waypoint"+playerScript.playerCurrentWaypoint.ToString()).transform;
//Disable as it's no longer needed (if you want laps you'd need to check this collidernumber in order against the current playerCurrentWaypoint
gameObject.active = false;
}