- Home /
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?
It sounds like two questions rolled into one. Do you want the player to have any free control, or are they always moving toward the check point?
They're always moving toward the check point. Here's a good example of what I want.
Star Fox is just a standard shoot ´m up, except it´s in 3d and the camera is behind the ship. Simply give your ship a constant forward (maybe slow it a little when turning) speed and use the arrow keys to move up/down/left/right, within the bounds of the 'tube' like level. What's your question precisely?
Answer by save · May 24, 2011 at 02:07 AM
Edited with a correct answer
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;
}
This gives you a complete freedom in creating your levels with just setting out the waypoints in order. The logic wouldn't care if the complete level is looping, swirling or just goes straight.
Actually, one more thing
How do I set it up so that the camera rotates 90 degrees when I press a button? (for example; the page down button)
edit I should probably ask that in a separate question
I was finally able to try the script out, but I received an error:
NewBehaviorScript.js(29,10): bce044 expecting (, found 'update'
As it has been stated earlier you can't have a faulty script anywhere in your project folder cause it will not compile (or make other scripts behave unexpectedly).
Your answer
Follow this Question
Related Questions
Drawing 2d line from a point on an object! 1 Answer
Saving a Trailrenderer? 0 Answers
Trail Renderer which ignores parent movement 0 Answers
Weapon Trails in Local Space 0 Answers
Raycast visible bullets 2 Answers