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 /
This question was closed Feb 16, 2017 at 02:12 PM by hexagonius for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by hexagonius · Feb 16, 2017 at 09:12 AM · cameratransformvector3transformationcross

Transform Screen Point to Transform extension

I have a problem I had a couple of times now and need a universal solution to it.
Basically the question is: How do I get the red vector to touch the blue one, no matter the length?

Vector scetch

The picture shows a camera and it's view frustum. The first orthogonal line is the near clipping plane. The red vector Indicates a point on screen transformed into world space on the plane. What I need is the position at the tip of the red vector.
The thick black bar is the plane/ Vector I want to cross with that arrow, in this case it's the forward vector (blue) of the green sphere. I know how to get the pink point just by transforming the screen position to that depth, but I have no idea how to get to the tip of the vector.
I don't want to use a raycast, because it's not just moving a character on a flat floor around but several places I need to do this. Like transforming a touch into the 2D movement plane of a spaceship. It works as long as camera looks perfectly straight at the plane, but at an angle I don't know how to do that.


Trying to use Project didn't help much because no matter how I put it I always the the shorter vector.

vectorproblem.png (38.9 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

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by hexagonius · Feb 16, 2017 at 02:12 PM

I pretty much came up with a solution myself:

 public Vector3 GetPointOnPlane(Vector3 planeCenter, Vector3 planeNormal, Vector3 origin, Vector3 direction){
         var p = new Plane(planeNormal, planeCenter);
         float pointToPlaneDistance = p.GetDistanceToPoint (origin);
         float partTowardsPlane = Vector3.Dot (direction, -planeNormal);
         float scalar = pointToPlaneDistance / partTowardsPlane;
         return origin + direction * scalar;
     }

Parameters:

  • planeCenter: some point in space that goes through the imaginative plane

  • planeNormal: the normalised direction the plane faces

  • origin: another point in space from where the direction and distance to plane are measured

  • direction: a direction vector of which the tip should finally end on the plane

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

Follow this Question

Answers Answers and Comments

99 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

Related Questions

Move to touch position 1 Answer

Why is my Camera rotation tilted after parenting it to head? 1 Answer

C# 2d Spawn Randomly along Camera Borders 1 Answer

nullifying targetObject after a Smooth LookAt Transition 2 Answers

UI objects move at different speeds on different resolutions 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