Skip to content

Instantly share code, notes, and snippets.

@Sammyjroberts
Created October 16, 2016 01:56
Show Gist options
  • Save Sammyjroberts/0f6d8caa8981a55c0a67087d8311c935 to your computer and use it in GitHub Desktop.
Save Sammyjroberts/0f6d8caa8981a55c0a67087d8311c935 to your computer and use it in GitHub Desktop.
Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit floorHit;
if(Physics.Raycast (camRay, out floorHit, camRayLength, floorMask))
{
// Create a vector from the player to the point on the floor the raycast from the mouse hit.
Vector3 playerToMouse = floorHit.point - ssr.transform.position;
// Ensure the vector is entirely along the floor plane.
playerToMouse.y = 0f;
ssr.transform.position = floorHit.point+(transform.position-floorHit.point)/2;
var scale = (ssr.transform.position-floorHit.point).magnitude;
Debug.Log(scale);
var length = scale*2;
if(length > 6) {
length = 6;
}
ssr.transform.localScale = new Vector3(length,1,0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment