• 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
1
Question by dmaxwell · Apr 08, 2010 at 12:08 PM · followvectorraytracktrain

how to calculate vector perpendicular to another and apply this to object direction?

This relates to the train problem I have. It is frustrating I know it is about vectors but I just can't get it.

So I have a simulation a cube with translation along forward direction I have a ray cast to the right (90 degrees to the direction of travel I have a rail track to the right not perpendicular to the translating box I have calculated the hit.point & hit.normal The hit.normal is being shown with the draw ray it is perpendicular to the track

To make sure the cube follows the track all I need to do is find the vector perpendicular to the hit.normal and apply this normal to the cubes transform.direction

Any help would appreciated.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
7

Answer by duck · Apr 08, 2010 at 07:21 PM

In 3D, there are an infinite number of vectors which are perpendicular to a single Vector in 3d space. This is because the perpendicular vector could point in any direction around the axis of the first vector.

What is generally more useful is to calculate a vector which is perpendicular to two other vectors. Those first two vectors essentially define a plane, and then it is possible to have a vector perpendicular to this plane.

For example, if you wanted to find a vector which is perpendicular sideways (along the groud) from your train track direction, you would use as the two input vectors:

  1. The track forward direction vector
  2. The world "up" direction vector

In addition, there can in fact be two vectors which are perpendicular to this plane, one pointing "up" relative to the plane, and one pointing "down". (or in the case of your train track, this would either be to the left or right of your track).

To get these perpendicular vector, you need to calculate the "Cross Product" of the initial two vectors. As it happens, Unity's Vector3 Class has a built-in Cross function which saves you from having to implement this yourself.

The order in which you pass the Vectors as the arguments to Cross (i.e. which is the "left hand side" and which is the "right hand side" vector) will determine whether you end up with the "up" or "down" version of the perpendicular vector.

Comment
Add comment · Show 3 · 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 dmaxwell · Apr 08, 2010 at 10:00 PM 0
Share

Ok thanks So I already have calculated a hit.normal from the train against the track section ,I need the the direction of the train to be perpendicular to this? This then becomes the trains new direction

avatar image dmaxwell · Apr 08, 2010 at 10:04 PM 0
Share

I have a test unity project on the forum http://forum.unity3d.com/viewtopic.php?t=48762 I have had a response but I cannot figure where I add the last vector to alter train direction

avatar image dmaxwell · Apr 09, 2010 at 02:49 PM 0
Share

so far with your help and help from stickystudios on forum I have it going round track but with a jitter see the result so far at http://forum.unity3d.com/viewtopic.php?p=296986#296986

avatar image
-10

Answer by Wyclife · Oct 31, 2011 at 11:42 AM

please help.(a) Find the equation for the plane perpendicular to the vector A=2¡+3j+6k and passingthrough terminal point of the vector B=¡+5J+3K

(b)From (a) find the distance from the origin to the plane

Comment
Add comment · Show 3 · 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 CHPedersen · Oct 31, 2011 at 11:43 AM 3
Share

This is not a math homework help site.

avatar image syclamoth · Oct 31, 2011 at 12:05 PM 2
Share

Neither was that post an answer to the question.

avatar image DragonBorn007 · Aug 09, 2014 at 05:04 PM 3
Share

Neither was that comment

the answer is 42

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to make boogies follow a track 1 Answer

How do you turn object to face a particular vector ? 1 Answer

How to make the object stop moving within a certain distance with the target. 1 Answer

Casting a Ray in the direction of the movement 1 Answer

I want to make a train go round a track using physics? 7 Answers


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