object fall problem

hi i have an object name “Target”, if i hit on Target it should fall back and should return back to same state as it was before hit. iitial position of target is (0,0,0) and rotation also (0,0,0). my problem is m able to fall it back but its not returning to its original state,

function Update()

{

if( hit.collider.name == “TARGET” )

{

startPosition = GameObject.Find(“Target1”).transform.rotation.x;

endPosition = -60 * Time.deltaTime * 3 ;

MoveObject(GameObject.Find(“Target1”).transform, startPosition, endPosition, 1.0);

}

}

function MoveObject (thisTransform :Transform, startPos : float, endPos : float, time : float)

{

var i = 0.0;

var rate = 1.0/time;

while (i < 1.0) 

{

    i += Time.deltaTime * rate;

    thisTransform.Rotate(endPosition, 0, 0);

    yield

}

}

m using this code to fall target, i tried thisTransform.Rotate(endPosition, 0, 0);
to get back target to original state but m not getting exact output, plz help

Man, you’re totally messing things: rotation is a quaternion, where X, Y, Z and W aren’t the familiar angles we know - these are the transform.eulerAngles.

Well, I tried to understand what you’re doing, but there are parts of the code missing - you haven’t posted the OnControllerColliderHit or OnCollisionEnter events which originated the hit variable.

Anyway, let’s find some way to do what you want. The first thing is to save the target position and rotation, so you can restore it when you want:

var target: Transform;
var targPos: Vector3;
var targRot: Quaternion;

function SavePosRot(){
  if (!target) // if target not defined yet...
    target = GameObject.Find("Target1"); // find it
  targPos = target.position;
  targRot = target.rotation;
}

If the target doesn’t move, you can call this function at Start. If it moves, you can call the function right before it’s hit the first time.

When you want to restore the target, you can call this function:

var time: float = 2.5; // time to return to position/rotation

function RestoreTarget(){
  var t: float = 0;
  var pos0 = target.position;
  var rot0 = target.rotation;
  while (t<1){
    target.position = Vector3.Lerp(pos0, targPos, t); // moves...
    target.rotation = Quaternion.Slerp(rot0, targRot, t);  // while rotating
    t += Time.deltaTime / time;
    yield;
  }
}

This will move and rotate the target to the original position and rotation during the time defined by time - apparently what you were trying to do. If you don’t need it to move to the original position, just to rotate to the original rotation, comment out the line with Vector3.Lerp.

All the code above must be in the same script.