Hello all ,
I have an object and I want to rotate it slowly and 90 degree per hit enter. I made it easily with transform.rotate but it turns 90 degree very fast. I want to slow down it , like an animation.
Thanks ,
Hello all ,
I have an object and I want to rotate it slowly and 90 degree per hit enter. I made it easily with transform.rotate but it turns 90 degree very fast. I want to slow down it , like an animation.
Thanks ,
What I would do, is specify an orientation when it’s hit, then use Quaternion.Slerp to interpolate to the desired rotation, for instance
var DesiredRotation : Quaternion = Quaternion.Identity;
function OnCollisionEnter() {
DesiredRotation *= Quaternion.Euler( 0, 90, 0 );
}
function Update() {
transform.rotation = Quaternion.Lerp( transform.rotation, DesiredRotation, Time.deltaTime );
}
[/quote]
Actually I need something like this :
function Update () {
if(Input.GetKeyDown(KeyCode.Return))
{
transform.Rotate(Vector3.forward , 90);
}
}
But it rotates too fast. I want it more slow. Anyone can help please ?
Make sure to link rotation and movement to Time. Otherwise, the rotation (or any movement) speed will be based on how fast your processor is.
90 * Time.deltaTime
When I do like 90 * Time.deltaTime it is only rotate 1 degree when I push Enter button. But I want to rotate 90 degree in every push and I want it slowly. Any other solutions ?
Well… the reason why you only rotate it like 1 degree then is because you only call the rotation function 1 time when you press the key. You should use something similar to this:
private var rotateTo : Quaternion;
function Start(){
rotateTo = transform.rotation;
}
function Update () {
if(Input.GetKeyDown("a")){
rotateTo = transform.rotation * Quaternion.Euler( 0, 0, 90 );
}
if(Quaternion.Angle(transform.rotation, rotateTo) > 0.5){
transform.Rotate(Vector3.forward, 90 * Time.deltaTime);
}
else if(transform.rotation != rotateTo){
transform.rotation = rotateTo;
}
}
You start the rotation when you press a key and keep rotation till the desired rotation is reached.