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?

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. :slight_smile:

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;
             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)