Advertisement
fivearchers

Snipped of using mouse arrow to target

Nov 5th, 2013
148
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.54 KB | None
  1. //This is a snippet of my controller code - basically newh and newv replace the standard stick inputs
  2. //  - so instead of trying to relative to the stick, it's pointing to the mouse arrow
  3.  
  4.  Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
  5.  Plane playerPlane = new Plane(Vector3.up, transform.position);
  6.  float hitdist = 0f;
  7.  if (playerPlane.Raycast (ray,out hitdist)) {
  8.         Vector3 targetPoint = ray.GetPoint(hitdist);
  9.     targetPoint=(targetPoint-transform.position).normalized;
  10.     newh=targetPoint.x;
  11.     newv=targetPoint.z;
  12.  }
Advertisement
RAW Paste Data Copied
Advertisement