Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by rageingnonsense · Dec 04, 2015 at 04:16 PM · vector3project

Vector3.Project, why do none of the examples I see work; why am I not getting this!?

Every time I try to use Vector3.Project; it NEVER WORKS the way I expect. I have tried numerous examples I have found on here, and they never ever work.

I have a line made of points A and B, and a point P that I would like to project on this line. I have tried this:

 Vector3 V1 = A - P;
 Vector3 V2 = Vector3.Project(V1, A.NormalTo(B));
 //return P + V2; this did not work either
 return A + V2;
 
 // NormalTo is an extension method I added to get a normal to a point. here is the definition:
 public static Vector3 NormalTo(this Vector3 from, Vector3 to) {
         return (to - from).normalized;
 }

The code was taken from the top post on here for Vector3.Project() (via google search).

This always places the point in some weird place not on the line, but in the proximity of it.

What in the hell am I doing wrong? This function mystifies me.

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
1
Best Answer

Answer by maccabbe · Dec 04, 2015 at 04:39 PM

Seems like

 Vector3 V1 = A - P;

should be

 Vector3 V1 = P - A;

if you're using onNormal = (B - A).normalized; and adding A back for return A + V2;

Comment
Add comment · Show 2 · 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 rageingnonsense · Dec 04, 2015 at 04:44 PM 0
Share

Thanks for the answer. I just tried that, but unfortunately it does not solve the problem. I still have the same issue. :/

avatar image rageingnonsense · Dec 04, 2015 at 05:01 PM 0
Share

I take that back. Your solution DOES work. I just had a secondary issue I was unaware of where A and B were not the points I thought they were. Thank you!! If you convert this to an answer, I'll mark it as accepted.

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

33 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

Related Questions

Object follows point while projecting on a line 1 Answer

Things that I don't get in Procedural Cave generation Tutorial 1 Answer

How do I find the rotation of a game object in relation to its grandparent 1 Answer

Object wont return to localposition of moving parent? 0 Answers

Detecting Distance from Object at any polint 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