• 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.

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

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

How to get a vector3 (postion) 1 unit away from another in the direction of a 3rd vector3? 2 Answers

Return grid points within a cube selection 1 Answer

Please help, bullet drop is wrong at certain angles ? 0 Answers

How to compute the change in vector when it's referential vector changes? 0 Answers

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