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 J.C Burns · Feb 27, 2016 at 03:21 AM · raycastcamera-movementplanetouchscreenpanning

Can't detect a plane with Raycast (not unity plane asset but the "public Plane plane;" sort of thing)

I am trying to create a touch-camera-panning-control through the use of what I have been calling 3D input. The theory goes as follows:

On the beginning of the touch a ray will be cast unto a plane (facing up/horizontal). The ray will be cast as a screenPointToRay from Input.GetTouch(0).position. The point where the ray collides with the plane will be recorded as "oldPoint" on the .moved phase of touch(0) another ray will be cast like the first and the intersection point recorded as "currentPoint". The difference between these points is the distance your finger has moved... relative to a 3D horizontal plane. [I am trying to achieve what others have called pixel perfect panning; if i were to touch a mountain on the screen and make a panning motion, the mountain would remain under my finger tip the whole time] The camera will be moved according to this distance. oldPoint is then set = currentPoint and a new point is recorded and assigned as the currentPoint as the cycle repeats and grants me my "pixel perfect panning" as I so dearly wish to achieve.

my problem lies in the first step, hindering the entirety of my genius scheme; I am trying to detect the raycast panRay's intersection with the plane panPlane using raycast, but it is not working.

 public Plane panPlane;
 
 // Use this for initialization
 void Start () {
     
 }
 
 // Update is called once per frame
 void Update () {
     if (Input.touchCount == 1)
     {
         if (Input.GetTouch(0).phase == TouchPhase.Began)
         {
             
             //panPlane.SetNormalAndPosition(new Vector3(0, 0, 0), Vector3.up);
             Ray panRay = GetComponent<Camera>().ScreenPointToRay(Input.GetTouch(0).position);
             float hitDist;

             if (panPlane.Raycast(panRay, out hitDist))
             {
                 Debug.Log("Hit");
             }
         }
         if (Input.GetTouch(0).phase == TouchPhase.Moved)
         {

         }
         if (Input.GetTouch(0).phase == TouchPhase.Ended)
         {

         }
     }

The if statement handling the detection of the ray is not returning true when i tap on the screen and ive been trying for hours in vain to discover why. I've spent hours on the api manual and it seems to me that all my syntax is correct; thoroughly stumping me.

Please help! Much appreciated!!!!!

P.S. if you see any flaws in my master plan feel free to point them out, if there is a better way to achieve this affect (with a perspective camera) PLEASE tell 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
0

Answer by Vinnie420 · Apr 10, 2016 at 11:43 AM

i think it is because you are using the "Plane" class, wich is not an actual plane, but more of a mathematical representation of a plane. (not exactly sure) If you have a plane as a gameobject in the scene, try changing "public Plane panPlane" to "public GameObject panPlane"

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

61 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

Related Questions

3D click and drag Camera Movement is shaking rapidly 0 Answers

Unity Error CS1729 The Type 'Plane' does not contain a constructer that takes 2 arguments 0 Answers

Camera Panning fail - erratic movement and then stops 1 Answer

Determining point coordinates on a plane for a known normal 1 Answer

Problem with Vector3.MoveTowards 2 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