Advertisement
NPSF3000

Screenpoint to point on plane.

Jul 11th, 2011
377
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. //  NPSF3000 - NPSF3001 randomgarbage gmail
  2. //  Free for personal/educational use - all risk is assumed by user.
  3. //  Attribution is nice :P
  4.  
  5.  
  6.     Vector3 GetMousePointInWorld_ZAxis()
  7.     {
  8.         //  This is quite simple:
  9.  
  10.         //  1) Get a ray from the mouse,
  11.         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  12.  
  13.         //  2) Intersect with a 'plane' (i.e find out where my mouse ray is when it intersects the z axis as defined by our object),
  14.         Plane plane = new Plane(new Vector3(0, 0, 1), transform.position);
  15.         float distance;
  16.         plane.Raycast(ray, out distance);
  17.  
  18.         //  3)  Return the point.
  19.         return ray.GetPoint(distance);
  20.  
  21.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement