Skip to content

Instantly share code, notes, and snippets.

@loldi
Created January 16, 2017 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loldi/a8e293d8359191ee7c638acfde7ac673 to your computer and use it in GitHub Desktop.
Save loldi/a8e293d8359191ee7c638acfde7ac673 to your computer and use it in GitHub Desktop.
ballToMouse = new Ray (ballPos.transform.position, Vector3.zero);
forceDir.z = 0f;
if (Input.GetMouseButtonDown (0)) {
mouseOrigin = Camera.main.ScreenToWorldPoint (Input.mousePosition);
mouseOrigin.z = 0f;
isPanning = true;
} else if (isPanning) {
Vector2 mouseDist = currentPos - mouseOrigin;
forceDir = mouseOrigin - currentPos;
magnitude = Mathf.Clamp (forceDir.magnitude, 1f, maxStretch);
currentPos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
currentPos.z = 0f;
if (mouseDist.sqrMagnitude > maxStretchSqr) {
ballToMouse.direction = forceDir;
currentPos = ballToMouse.GetPoint (maxStretch);
forceDir = ballToMouse.GetPoint (maxStretch);
shotDir.SetPosition (0, ballPos.transform.position);
shotDir.SetPosition (1, ballToMouse.GetPoint(maxStretch));
} else {
shotDir.SetPosition (0, ballPos.transform.position);
shotDir.SetPosition (1, ballPos.transform.position + forceDir);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment