- Home /
 
               Question by 
               biohazard · Jun 16, 2011 at 09:13 AM · 
                javascriptmouse  
              
 
              Rotating a Sphere with the mouse?
EDIT : Added my code snippet which tries to "grab and drag" the mouse to its actual rotation. it's not working :/
 if(Input.GetMouseButton(0))
 {
     var ziel : Vector3 = Kamera.ScreenToWorldPoint(Input.mousePosition);
     var relativePos = kugel.transform.position - ziel;
     var Rotation = Quaternion.LookRotation(relativePos);
     kugel.transform.rotation = Rotation;
 }
Btw "kugel" is german for Sphere :p
Quaternion.LookRotation might be the wrong way. please help me guys =/
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by FordPrefect · Jun 16, 2011 at 10:57 AM
  var rotationSpeed = 10.0;
 var lerpSpeed = 1.0;
 
 private var speed = new Vector3();
 private var avgSpeed = new Vector3();
 private var dragging = false;
 private var targetSpeedX = new Vector3();
 
 function OnMouseOver() 
 {
     dragging = true;
 }
 
 function Update () 
 {
 
     if (Input.GetMouseButton(0) && dragging) {
         speed = new Vector3(-Input.GetAxis ("Mouse X"), Input.GetAxis("Mouse Y"), 0);
         avgSpeed = Vector3.Lerp(avgSpeed,speed,Time.deltaTime * 5);
     } else {
         if (dragging) {
             speed = avgSpeed;
             dragging = false;
         }
         var i = Time.deltaTime * lerpSpeed;
         speed = Vector3.Lerp( speed, Vector3.zero, i);   
     }
 
     transform.Rotate(Vector3.up, speed.x * rotationSpeed, Space.World);
 
 }
Try something like this, I am working on something similar, but not the same.
PARTIALLY right :)
BUT! if i want to rotate it without being limited to one axis, how do i do that? (:
also, when i rotate it, get the mouse off it, and mouse over again the sphere rotates with the old values
Gimme a couple of seconds, ill have a look after work
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                