Hi, I'm trying to simulate a 'jog' dial, like the dial you get on a stereo or mixing desk. It needs to rotate in a clockwise anti-clockwise manner in response to an iPhone swipe gesture, that is it should continue spinning for a second after swiping/releasing before slowing to zero rotation, but should stop dead on a non-swipe touch release. I'm not at my Unity computer right now but my code so far just has a disc to act as a dial which turns left/right on a finger swipe, but I can't seem to get the 'accelerated' dial-turn movement described above. Any suggestions?
use physics to turn it then the physics will handle it. otherwise you will have to replicate what the physics does by giving it a "turn power" that degrades continously
Why not base how far the dial turns based on iPhoneTouch.deltaPosition.x, and if iPhoneTouch.phase == iPhoneTouchPhase.Ended, lerp the amount the dial turns down to zero based on a time value that is proportional to iPhoneTouch.deltaPosition.x?
The deltaPosition method sounds interesting. I've been using Unity iPhone for just a few days though, I'd like to get to grips with using the delta. data; If anyone can throw some example code up that I can fidle with I'd be grateful, particularly along the lines of spinning/rotating an object with the touchscreen.
file:///Applications/Unity%20iPhone/Unity%20iPhone.app/Contents/Documentation/Documentation/ScriptReference/Transform.RotateAround.html Code (csharp): function Update() { transform.RotateAround (transform.position, Vector3.forward, iPhoneInput.GetTouch(0).deltaPosition.x); }
Ok, I'm having a little trouble with the code here. I tried this example from the manual: // Moves object according to finger movement on the screen var speed:float = 0.1; function Update () { if (iPhoneInput.touchCount > 0 iPhoneInput.GetTouch(0).phase == iPhoneTouchPhase.Moved) { // Get movement of the finger since last frame var touchDeltaPosition:Vector2 = iPhoneInput.GetTouch(0).deltaPosition; // Move object across XY plane transform.Translate (-touchDeltaPosition:Vector2.x * speed, -touchDeltaPosition:Vector2.y * speed, 0); } } and I get a "expecting ) found :" error in the transform.Translate line of code. I can't seem to get this code working ?
Please use the Code button (found to the right of "Message body") to make the code easier to read. Like this! Code (csharp): // Moves object according to finger movement on the screen var speed:float = 0.1; function Update () { if (iPhoneInput.touchCount > 0 iPhoneInput.GetTouch(0).phase == iPhoneTouchPhase.Moved) { // Get movement of the finger since last frame var touchDeltaPosition : Vector2 = iPhoneInput.GetTouch(0).deltaPosition; // Move object across XY plane transform.Translate(-touchDeltaPosition.x * speed, -touchDeltaPosition.y * speed, 0); } } Your problem was that you were putting the ": Vector2" after touchDeltaPosition, twice, after it had already been defined as a Vector2. Ouch, that's really in the manual as is! :x I'm reporting a bug about the documentation right now.
I didn't think it read right but I convinced myself it was....this vector stuff is rather new and I'm up to my neck in code and thinking....the manual is always right! Thanks though Jessy, i'm making ground on this now.