Created
January 16, 2017 22:07
-
-
Save loldi/a8e293d8359191ee7c638acfde7ac673 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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