x


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 =/

more ▼

asked Jun 16 '11 at 09:13 AM

biohazard gravatar image

biohazard
288 36 42 46

it works once and after that...nothing :/

Jun 16 '11 at 09:40 AM biohazard

thanks save. but i'm working with Javascript, not C# :/

Jun 16 '11 at 09:54 AM biohazard

can't anyone help? D:

Jun 16 '11 at 10:07 AM biohazard

@save i always go SLERP with my coffee :p

Jun 16 '11 at 11:35 AM biohazard
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
 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.

more ▼

answered Jun 16 '11 at 10:57 AM

FordPrefect gravatar image

FordPrefect
31 3 3 5

PARTIALLY right :)

BUT! if i want to rotate it without being limited to one axis, how do i do that? (:

Jun 16 '11 at 12:51 PM biohazard

also, when i rotate it, get the mouse off it, and mouse over again the sphere rotates with the old values

Jun 16 '11 at 12:56 PM biohazard

Gimme a couple of seconds, ill have a look after work

Jun 16 '11 at 02:15 PM FordPrefect
Jun 17 '11 at 06:17 AM biohazard
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5049
x3716
x3442
x3314
x981

asked: Jun 16 '11 at 09:13 AM

Seen: 1245 times

Last Updated: Jun 17 '11 at 06:17 AM