• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by lavik1988 · May 23, 2011 at 10:47 PM · trailcheckpoint

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?

Comment

People who like this

0 Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image GesterX · May 23, 2011 at 10:50 PM 0
Share

So you want to know how to move towards a given point?

avatar image lavik1988 · May 23, 2011 at 10:58 PM 0
Share

I suppose you could say that

avatar image _Petroz · May 24, 2011 at 12:37 AM 0
Share

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?

avatar image lavik1988 · May 24, 2011 at 12:44 AM 0
Share

They're always moving toward the check point. Here's a good example of what I want.

http://www.youtube.com/watch?v=xja9bjOOePk

avatar image Joshua · May 24, 2011 at 12:45 AM 0
Share

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?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image

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; 
     }

Example project here

Comment
lavik1988

People who like this

1 Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image save · May 24, 2011 at 02:25 AM 0
Share

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.

avatar image lavik1988 · May 24, 2011 at 02:28 AM 0
Share

I think this is what I was looking for. Thank you

avatar image lavik1988 · May 24, 2011 at 02:39 AM 0
Share

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

avatar image lavik1988 · May 28, 2011 at 03:12 AM 0
Share

I was finally able to try the script out, but I received an error:

NewBehaviorScript.js(29,10): bce044 expecting (, found 'update'

avatar image save · May 29, 2011 at 09:56 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

enabling trail renderer 1 Answer

Depth errors on generated meshes 1 Answer

Trail behind standing player 1 Answer

[Solved] How to correctly use TrailRenderer.GetPositions 1 Answer

How i make a infinite trail whith TrailRenderer? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges