Created
June 18, 2011 18:29
-
-
Save erskingardner/1033377 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
var dial : GameObject; | |
var snoozeButton : GameObject; | |
var dialEasing : float = 0.2; | |
private var dialDrag1 = false; | |
private var dialTargetAngle = 0.0; | |
private var dialActualAngle = 0.0; | |
private var dialVelocity = 0.0; | |
function Start () { | |
} | |
function Update () { | |
if (Input.touchCount == 1){ | |
var touch = Input.GetTouch(0); | |
var ray = Camera.main.ScreenPointToRay(touch.position); | |
var hit : RaycastHit; | |
if (Physics.Raycast(ray, hit)){ | |
var setDate = GameObject.Find("Camera - Set Date"); | |
// Clock dial 1 is the target at the beginning of the touch | |
if (Camera.main.transform.position == setDate.transform.position && hit.collider.gameObject == dial && touch.phase == touch.phase.Began){ | |
dialDrag1 = true; | |
} | |
} | |
if (dialDrag1) { | |
dialTargetAngle = CalculateTargetAngle(dialTargetAngle, touch.deltaPosition.y * 2); | |
var finishedDialEase = Mathf.Approximately(dialTargetAngle, dialActualAngle); | |
if (!finishedDialEase) { | |
// startRotation = dial.transform.rotation; | |
// endRotation = Quaternion.AngleAxis(((touch.deltaPosition.y / Screen.height) * 360), Vector3.up); | |
dialActualAngle = CalculateActualAngle(dialActualAngle, dialTargetAngle); | |
dial.transform.Rotate(Vector3.up * Time.deltaTime * (dialTargetAngle - dialActualAngle)); | |
} | |
} | |
} | |
} | |
function CalculateTargetAngle (current : float, increment : float) { | |
var newTargetAngle = 0.0; | |
newTargetAngle = current + increment; | |
return newTargetAngle; | |
} | |
function CalculateActualAngle (currentDial : float, targetDial : float) { | |
return Mathf.SmoothDamp(currentDial, targetDial, dialVelocity, dialEasing); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment