Comments and answers for "Slowing Down Rotation Speed"
http://answers.unity.com/questions/640938/slowing-down-rotation-speed.html
The latest comments and answers for the question "Slowing Down Rotation Speed"Comment by Shapes on Shapes's answer
http://answers.unity.com/comments/648420/view.html
Thank you so much the script works great and it was exactly what i was looking for.Mon, 24 Feb 2014 05:20:15 GMTShapesComment by Scribe on Scribe's answer
http://answers.unity.com/comments/643490/view.html
When you are rotating in two axis simultaneously it becomes quite a bit harder to calculate the rotation as you don't have a fixed axis to pivot around so I don't think you can extend the previous method to work in 2 axis (though maybe someone can correct me).
I feel like there should be an easier way to do this but I can't think of one though I may investigate using the cross product of the two axis and rotating about that.
Anyway, in the meantime this produces a very smooth rotation that will always finished locked to a multiple of 90degrees.
var targetAngle : Quaternion;
var startAngle : Quaternion;
var forward : Vector3;
var right : Vector3;
var up : Vector3;
private var startTime : float;
function RoundVector(v : Vector3) : Vector3{
return Vector3(Mathf.Round(v.x), Mathf.Round(v.y), Mathf.Round(v.z));
}
function RotateAround(vF : Vector3, vR : Vector3, vU : Vector3, axis: Vector3, angle: float) : Quaternion{
var rot: Quaternion = Quaternion.AngleAxis(angle, axis); // get the desired rotation
forward = RoundVector(rot*vF);
right = RoundVector(rot*vR);
up = RoundVector(rot*vU);
startTime = Time.time;
startAngle = transform.rotation;
targetAngle = rot * targetAngle;
}
function Start(){
startAngle = transform.rotation;
targetAngle = startAngle;
forward = RoundVector(transform.forward);
right = RoundVector(transform.right);
up = RoundVector(transform.up);
}
function Update () {
if(Input.GetKeyDown(KeyCode.RightArrow)){
RotateAround(forward, right, up, Vector3.up, -90);
}else if(Input.GetKeyDown(KeyCode.LeftArrow)){
RotateAround(forward, right, up, Vector3.up, 90);
}
if(Input.GetKeyDown(KeyCode.UpArrow)){
RotateAround(forward, right, up, Vector3.right, 90);
}else if(Input.GetKeyDown(KeyCode.DownArrow)){
RotateAround(forward, right, up, Vector3.right, -90);
}
transform.rotation = Quaternion.Slerp(startAngle, targetAngle, Time.time-startTime);
}
ScribeWed, 19 Feb 2014 01:23:11 GMTScribeComment by Shapes on Shapes's answer
http://answers.unity.com/comments/642616/view.html
Thank you so much for the script, it was exactly what i was looking for. The only problem I have found with the script is that when i play the game i can rotate the cube left (with left arrow) and right(with the right arrow) but not up and down, I have change the script so that the cube can move up and down but not left or right. Is there any way that i can rotate the cube left, right, up, and down?Tue, 18 Feb 2014 04:43:21 GMTShapesComment by Scribe on Scribe's answer
http://answers.unity.com/comments/641568/view.html
Then you transform.Rotate is probably not the best method to use. Rotate is designed for continuous rotations, not so much for where you want to rotate a fixed amount. You can still do it with rotate but it becomes more difficult. I answered a similar question to this recently maybe you can make use of the code:
private var startAngle : float;
private var targetAngle : float;
private var startTime : float;
var smooth : float = 1.0; // The number of seconds taken to rotate
private var angle : float;
function Start(){
angle = transform.eulerAngles.y;
}
function Update () {
if(Input.GetKeyDown(KeyCode.RightArrow)){
startTime = Time.time;
startAngle = angle;
targetAngle = targetAngle + 90;
}else if(Input.GetKeyDown(KeyCode.LeftArrow)){
startTime = Time.time;
startAngle = angle;
targetAngle = targetAngle - 90;
}
angle = Mathf.LerpAngle(startAngle, targetAngle, (Time.time - startTime)/smooth);
transform.eulerAngles = Vector3(0, angle, 0);
}
This sets the transform.eulerAngles directly rather than using Rotate.
ScribeMon, 17 Feb 2014 02:30:08 GMTScribeComment by Shapes on Shapes's answer
http://answers.unity.com/comments/641438/view.html
Thank you for the suggestions, but I am trying to rotate the cube 90 degrees every time i press a button.Sun, 16 Feb 2014 22:06:55 GMTShapesAnswer by Scribe
http://answers.unity.com/answers/641185/view.html
You can slow it down very simply by giving it a value smaller than 90 such as:
transform.Rotate(0, 1, 0);
which would rotate the object at 1 degree per frame. If you have a set 'degrees per second' that you want to rotate by you can use Time.deltaTime to achieve that effect:
transform.Rotate(0, 10*Time.deltaTime, 0);
will rotate at 10 degrees per second.
ScribeSun, 16 Feb 2014 15:56:44 GMTScribe