Unity C# use Transform.RotateAround with touch to move camera around target -


so looking @ changing transform.rotatearound script touch input. if rid of "input.getaxis", camera rotates on own around target. cant seem figure out how format code position of touch string use this. if has tips awesome!

here code:

using unityengine; using system.collections;  [addcomponentmenu("camera-control/mouse orbit zoom2")] public class mouseorbitimproved2 : monobehaviour {  public float speed;  public transform target; public float rotatespeed; public transform camera = camera.main.transform; public vector3 camposition; public float camspeed; public float mindistance; public float maxdistance; //private vector3 movedirection = vector3.zero; //private vector3 movedirection = target.position; public float perspectivezoomspeed = 0.5f;        // rate of change     of field of view in perspective mode. public float orthozoomspeed = 0.5f;        // rate of change of orthographic size in orthographic mode.  void start() {      //camposition = camera.transform.position; }  public void update() {     if (input.touchcount == 1) {         transform.lookat(target);         touch touchswipe = input.gettouch(0);         string position = touchswipe.deltaposition;           transform.rotatearound(target.position, vector3.up, input.getaxis(position)* speed);         transform.rotatearound(target.position, vector3.forward, input.getaxis(position)* speed);     }          transform.lookat(target);     /*         float scroll = input.getaxis("mouse scrollwheel");         if (scroll != 0)         {             // calculate new position first...             camposition += transform.forward * scroll * camspeed;             // compare limits:             float distancetotarget = vector3.distance(target.position, camposition);             // can clamp movement min , max distances:             if (distancetotarget > maxdistance){ // clamp @ maxdistance...                 camposition = target.position - maxdistance * transform.forward;             }             if (distancetotarget < mindistance){ // or @ mindistance                 camposition = target.position - mindistance * transform.forward;             }             // finally, update actual camera position:             transform.position = camposition;         // set camera position         }         */      // if there 2 touches on device...     if (input.touchcount == 2)     {         // store both touches.         touch touchzero = input.gettouch(0);         touch touchone = input.gettouch(1);          // find position in previous frame of each touch.         vector2 touchzeroprevpos = touchzero.position - touchzero.deltaposition;         vector2 touchoneprevpos = touchone.position - touchone.deltaposition;          // find magnitude of vector (the distance) between touches in each frame.         float prevtouchdeltamag = (touchzeroprevpos - touchoneprevpos).magnitude;         float touchdeltamag = (touchzero.position - touchone.position).magnitude;          // find difference in distances between each frame.         float deltamagnitudediff = prevtouchdeltamag - touchdeltamag;          // if camera orthographic...         if (camera.main.orthographic)         {             // ... change orthographic size based on change in distance between touches.             camera.main.orthographicsize += deltamagnitudediff * orthozoomspeed;              // make sure orthographic size never drops below zero.             camera.main.orthographicsize = mathf.max(camera.main.orthographicsize, 0.1f);         }         else         {             // otherwise change field of view based on change in distance between touches.             camera.main.fieldofview += deltamagnitudediff * perspectivezoomspeed;              // clamp field of view make sure it's between 0 , 180.             camera.main.fieldofview = mathf.clamp(camera.main.fieldofview, 0.1f, 179.9f);         }           } }  public void changetoaxial (){     camera.main.transform.position = new vector3 (45.3f,234.5f,66.9f); }  public void changetosagright (){     camera.main.transform.position = new vector3 (28.13f,76.41f,222.68f); }  public void changetosagleft (){     camera.main.transform.position = new vector3 (49.36f,66.85f,-93.78f); }  public void changetocoronal () {     camera.main.transform.position = new vector3 (-71.6f,69.66f,66.29f); } 

}

i think may best if @ question , answer unity forum unit 5 forum rotating camera touch. should work input.gettouch instead of input.getaxis. hope helps. aware script in javascript, shouldn't need whole script.


Comments