Hey all. I am making a simple splash page for my site. I need to drag a cube in place, Mouse Orbit style, but only while clicking. So I modified the Mouse Orbit script to only work while holding the mouse down. Now my problem is that when you release the mouse button, the cube instantly halts. I want it to spin to a halt slowly. What should I do to make that happen? Thanks!
Do you want make something spin, and then slow down and stop. It would probably be something like this:
var axis : Vector3 = Vector3 (0, 1, 0);
var spinTime : float = 5.0;
var spinSpeed : float = 80.0;
function Start ()
{
SpinOut ();
}
function SpinOut ()
{
var originalTime : float = Time.time;
var wantedSpeed : float = (originalTime + spinTime) - Time.time;
while (Time.time < originalTime + spinTime)
{
transform.Rotate (axis.normalized * wantedSpeed * Time.deltaTime * spinSpeed);
wantedSpeed = (originalTime + spinTime) - Time.time;
yield;
}
}
Does this work for you?
Thanks for the sample code.
I too am interested in something like this, however, I think what NickAVV and I would like to accomplish is to manipulate the spinning directly when the mouse if pressed (or in my case a swipe gesture on iPhone), and then when finger (or button) is released, dampen the motion of the spinning to gradually come to a complete stop.
An additional problem is using transform.Rotate on a cube object (in my case) and getting the rotation vector for World space instead of local space.
Can anyone provide additional insight?
I’m currently looking into this.
Trying to get a cube to spin on either the X or the Y axis depending on where the user drags their mouse.
I’ve been playing a little with iTween to get the ball rolling…
function OnMouseDrag () {
iTween.RotateTo(gameObject, {"x":180, "time": 2, "onComplete": "MoveBack"});
}
Would I be right in saying that with the mouse commands, it would work the same on a touchscreen too?