# X and Y translation limits and checkpoints

I’ve been trying to make a game similiar to Star Fox and Panzer Dragoon.

A few weeks ago, I found a model viewer for the Star Fox SNES rom. It also gives information on how the game works.

Each level consists of a series of check points. The player is continually moving towards these until the check point is reached.

Does anyone know how to set this up in unity? Or how to limit the X and Y translation/rotation?

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{