function onMouseOver(){
if(Input.GetMouseButtonDown(0)){
transform.Rotate(Vector3.forward * 90);
}
}
Only instead of "snapping" rotation into the next 90 degrees, I'd think it would be better for the rotation to be visible. To be somehow "eased", and for the player to see, that the plane has rotated. not just snapped/teleported into place.
it should be an easy question. does anybody know the answer?
thank you in advance.
This is based on Eric's MoveObject snippet that he's posted around the place.
function Update ()
{
if ( Input.GetMouseButtonDown(0))
RotateObject(transform.rotation,Quaternion.Euler(transform.rotation.eulerAngles + Vector3.forward * 90),2.0);
}
function RotateObject(startRot : Quaternion, endRot : Quaternion, rotateTime : float)
{
var i = 0.0;
var rate = 1.0/rotateTime;
while (i < 1.0)
{
i += Time.deltaTime * rate;
transform.rotation = Quaternion.Lerp(startRot, endRot, Mathf.SmoothStep(0.0, 1.0, i));
yield;
}
}
There might be a better way to calculate the 'endRot' Quaternion, but I've tested this and it works. You can pass in the 'rotateTime' and it eases in and out the movement using SmoothStep.