• 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
0
Question by hobomaniac · Jun 20, 2012 at 06:19 PM · pathrail

Free X/Y movement while on a Z axis rail

I've been working on prototyping a star fox like movement system where the player only controls the x and y movements of a ship within a set boundary while the ship moves along a set path. I currently have a ship the moves in one direction while the player can control its position on screen. Where I'm having issues is how I would go about getting this whole rig to move on a preset path. I have no doubt that I could solve this in some complicated round-about manner but I wanted to know if there is some straight forward solution that could save me a lot of wasted time. Any hint or push in the right direction would be great. Thanks.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by hathol · Jun 20, 2012 at 06:50 PM

Essentially: use the transforms local axes to do the translation and use your path to determine the orientation. Something like

 //get your offset direction
 Vector3 direction = Vector3.zero;
 if(goRight)
     direction += transform.right;
 else if(goLeft)
     direction += -transform.right;
 if(goUp)
     direction += transform.up;
 else if(goDown)
     direction += -transform.up;

 //add your forward movement
 Vector3 zDirection = (Vector3)nextPositionOnPath - (Vector3)currentPositionOnPath;
 direction += zDirection.normalized;

 transform.position = transform.position + direction*speed*Time.deltaTime;
 transform.rotation = Quaternion.LookRotation(zDirection);

Just add your boundary check in there. It's not a final solution but it should get you started

Comment
Add comment · 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

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Camera to smoothly LookAt() a series of empty objects along a curved path that act as a 'rail' 3 Answers

Camera position on path Proportional to Player'sposition 0 Answers

Creating a multi-rail track, that the player can interchange. 0 Answers

Script for auto movement with intersections 0 Answers

Slotcar game 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges