Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 ShawnAlberts · Feb 12, 2019 at 07:32 PM · vector3project

I don't understand Vector3.ProjectOnPlane...

I can't seem to wrap my head around what vectors I have to put into ProjectOnPlane. To try to understand it, I've created two boxes with cast rays directly below them. alt text

So I have the plane normal (as shown as the green line) and the points that hit the plane. What values do I need to put into Vector3.ProjectOnPlane(vector, planeNormal) to get the intended result?

slope-example.jpg (104.0 kB)
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
0
Best Answer

Answer by Captain_Pineapple · Feb 12, 2019 at 10:12 PM

Hey there,

b has to be the planes normal. a is the vector that will be projected on the plane defined by the normal b. you should get the normal from the downward raycast hits hit normal.

Does this clear things up?

Comment
Add comment · Show 6 · 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 ShawnAlberts · Feb 12, 2019 at 10:23 PM 0
Share

So if the green line in the image is the normal, what would "a" be?

avatar image Captain_Pineapple ShawnAlberts · Feb 13, 2019 at 12:46 PM 0
Share

I'm afraid to answer that you have to provide some information on what you want to do. If you want for example the "slope-vector" in character forward direction then a is transform.forward.

But as i said it depends on your usecase. Let us know some more on what you plan to do with the result.

avatar image ShawnAlberts Captain_Pineapple · Feb 13, 2019 at 01:13 PM 0
Share

Sorry for all the confusion, I'm a tad new to unity. I have set up a scene like the image, and I'd like to project a vector on the plane using the two rays that are being cast on it by the boxes. So what I know is

 projectedVector = Vector3.ProjectOnPlane(a, rayB.normal);

But I don't know what to put in "a".

Show more comments
avatar image
1

Answer by Bunny83 · Feb 12, 2019 at 07:58 PM

ProjectOnPlane will project a direction vector onto the plane, not positions. Just think about removing any offset along the given plane normal from the vector. So if you move the origin of the vector somewhere onto the plane, the resulting vector will lay completely on that plane.


ProjectOnPlane is literally just defined as:

 public static Vector3 ProjectOnPlane(Vector3 vector, Vector3 planeNormal)
 {
     return vector - Vector3.Project(vector, planeNormal);
 }

This is what i just mentioned. Project will project the vector onto the normal vector, returning only the part of the vector along the normal. This amount is subtracted from the original vector which results in a vector that is parallel to the plane surface.


Note that from your image it's not clear what your "intended result" is. Maybe you wanted to actually cast a ray onto a plane? In that case you may want to use Unity's Plane struct and its Raycast method.

Comment
Add comment · Show 1 · 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 ShawnAlberts · Feb 12, 2019 at 09:27 PM 0
Share

Thanks for the reply. The goal of what I'm trying to do it to get a vector to project along the plane, I'm using this to try to get smooth slope movement for my character controller so I can move it parallel to the surface of which the character is moving on. I do understand what Project and ProjectOnPlane do, I'm just confused as to what vectors are put into the method.

 projectedVector = Vector3.ProjectOnPlane(a, b);

I'd just like to know what to replace "a" and "b" with.

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

124 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

What is Vector3.Exclude for? 2 Answers

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

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

problem in exporting unity 5 project 0 Answers

Are there project files for a game like.... 0 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