Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 kurasu1415 · Feb 07, 2015 at 03:01 AM · vector3mathprojectrelative

Project a position onto a plane whose normal isn't at the origin.

I need to project an object's position onto a plane. Unity provides this method :

 Vector3.ProjectOnPlane(Vector3 positionToProject, Vector3 normalOfPlane)

This method projects a Vector 3 onto a plane whose normal is at the origin. I have been trying to take the result from this and apply it to the position of another object, but every attempt so far has failed. Is there a way to project on to a plane defined by a normal that isn't on the origin?

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
1

Answer by asafsitner · Feb 18, 2017 at 04:42 AM

I know it's an old question, but as I ran into the same problem today, I'll answer:
Unity's built-in methods do not have an option to specify the plane's origin, however, it's possible to do so manually and use Plane.Raycast to find the intersection point, for example:

 private void ProjectTransformOnPlane(Transform objectToProject, Vector3 planeOrigin, Vector3 planeNormal)
         {
             Plane projectionPlane = new Plane(planeNormal, planeOrigin);
             float distanceToIntersection;
             Ray intersectionRay = new Ray(objectToProject.position, objectToProject.forward);
             if (projectionPlane.Raycast(intersectionRay, out distanceToIntersection))
             {
                 objectToProject.position = objectToProject.position + objectToProject.forward * distanceToIntersection;
             }
     }

This principle can be modified and applied to different scenarios, but in each of them, we must have the origin and direction of the vector we'd like to project onto the plane.
In this case, I used the Transform's forward to find its direction, but any other vector can be used.

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
avatar image
0

Answer by PraetorBlue · Feb 14, 2019 at 01:55 AM

Since you are working with Vectors and not Rays, it is safe to conceptualize all vectors as being "on the origin".

What the projection of the vector on the plane will do is give you the component of the vector which is parallel to the plane. You can then do with this projection whatever you want. Your question is a little unclear with regards to your use case, so it's hard to say much more than that.

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Math Question : How to Get a Point on a Ray which is EXACTLY 5 units away from Vector3.Zero? 5 Answers

Extending a vector? 4 Answers

Average of Vectors [Math] 1 Answer

Rotate 3d vector based on local forward 1 Answer

Angle between two vector3 relative to a certain point 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