- Home /
Quaternion.identity?
I want to reset the rotation of an object once it reaches a specific coordinate on the z axis...
I have this which works fine at the moment...
var target : GameObject;
function Start () {
}
function Update () {
if(transform.position.z == -1.0f)
target.transform.rotation = Quaternion.identity;
}
However instead of the reset being an instant change, is there a way of adjusting the script so that the object actually rotates back to the points of 0,0,0 instead of instantly reverting to 0,0,0?
Answer by Oana · Jul 02, 2013 at 12:45 PM
Try something like this:
var rotateBack = false;
var speed = 10;
function Update(){
if (transform.position.z == -1.0f) rotateBack = true;
if (rotateBack){
if (target.transform.rotation == Quaternion.identity){
rotateBack = false;
}else{
target.transform.rotation = Quaternion.Lerp(target.transform.rotation, Quaternion.identity, speed*Time.deltaTime);
}
}
}
(not tested in editor, but should give you an idea of how to do it)
Thank you, this is how I solved my problem...
var target : GameObject;
var speed = 10;
function Update(){
if (transform.position.z == -1.0f)
target.transform.rotation = Quaternion.Lerp(target.transform.rotation, Quaternion.identity, speed*Time.deltaTime);
}
While this will somehow give you a result that kind of looks like something you want, this is not how you use lerp. The duration of the smooth motion will be dependent on the framerate and completely unpredictable. It's been discussed so many times now
Answer by lighting · Jul 02, 2013 at 12:42 PM
Please use Quaternion.Lerp as described here: in the documentation, where target Rotation will be Quaternion.identity. I hope this is what you're looking for. :)
Cheers for putting me on to lerp! Will come in very handy.
Your answer