Camera. Screenpointtoray (), camera. Screentoworldpoint () and Raycast ()

Source: Internet
Author: User

  1. Camera. Screenpointtoray (input.mouseposition), since Camera.tranform.position Input.mouseposition fired a ray and returned to Ray
  2. Camera. Screentoworldpoint (Input.mouseposition+new Vector3 (0, 0, (XXX))), converts screen coordinates to world coordinates, but must assign Z-values, which should be the projection of the camera to the plane of the point
  3. Do not forget distance parameters, using Layermask may be confused with distance
  4. 1Ray Ray =Camera.main.ScreenPointToRay (input.mouseposition); 2 Raycasthit hit;3 4             if(Physics.raycast (Ray, outhit,layermask))5             {6Vector3 dir = hit.point-camera.main.transform.position;//dir is a vector of points to which the camera points to a ray7Vector3 forward = Camera.main.transform.forward;//unit vector pointing directly ahead of the camera8Debug.Log ("Camera.main.ScreenToWorldPoint (input.mouseposition)" 9+Camera.main.ScreenToWorldPoint (input.mouseposition)Ten+NewVector3 (0,0, (Vector3.dot (dir, Forward)));//Vector3.dot (dir, forward) is the point multiplication of dir and forward, and the geometric meaning is the projection of Dir on the forward. OneDebug.Log ("Hit.point"+hit.point); A}
    View Code

    

Camera. Screenpointtoray (), camera. Screentoworldpoint () and Raycast ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.