Answers for "Resetting transform's original position and rotation after using transform.rotateAround"
http://answers.unity.com/questions/170300/resetting-transforms-original-position-and-rotatio.html
The latest answers for the question "Resetting transform's original position and rotation after using transform.rotateAround"Answer by aldonaletto
http://answers.unity.com/answers/170305/view.html
You must first save the localPosition and localRotation of the model, do the rotation or whatever you want, then restore these local settings. If you just assign them, the model will be "teleported" to the original position/rotation; if you want it to smoothly return to the original settings, you can use the "Lerp filter":
<pre>
// save the original settings (assuming model is the model transform)
var rot0 = model.localRotation;
var pos0 = model.localPosition;
// do the movement/rotation as you're already doing
// then restore them using Lerp (assuming this is in Update):
var dt = Time.deltaTime * 2.3; // 2 to 5 give reasonable results
model.localRotation = Quaternion.Slerp(model.localRotation, rot0, dt);
model.localPosition = Vector3.Lerp(model.localPosition, pos0, dt);
</pre>
The actual implementation depends on your original script. If you can't find the best way to match this code to your script, post the script here and we'll try to help you.
**EDITED:** From your script, I suppose you want to "bank" your model based on a pivot 5 units above the center. The easiest way is to do that is to have an intermediate empty object (let's call it Pivot) with local position = (0,5,0). The model is childed to the Pivot, and the Pivot is childed to your character, like this:
<pre>
Character
Pivot
Model
</pre>
When banking to any side, just set the Pivot localEulerAngles like this:
<pre>
Pivot.localEulerAngles = Vector3(0, 0, angle);
</pre>
It's better to set the localEulerAngles as a whole, instead of just setting its **z** component - setting individual components causes small drifts that may accumulate and let the object in a weird position after some time.<br>
All Rotate functions (Rotate, RotateAround) have the same problem: you loose the angle information, because *you just can't trust in the returned euler angles!* The 359/-1 uncertainty is just the tip of the iceberg: after some rotations, the craziest angle combinations may be returned, and you have no chance to correctly interpret them.<br>
For this reason, always avoid reading euler angles; if you must rotate something and still know the euler angle at any time, do the inverse thing: keep the angle in a variable, increment or decrement it (always modulo 360) and set the euler angles at once using a Vector3 structure - like in this generic Rotate function:
<pre>
var xAngle: float = 0;
var yAngle: float = 0;
var zAngle: float = 0;
function RotatePrecisely(angX: float, angY: float, angZ: float){
xAngle = (xAngle + angX) % 360;
yAngle = (yAngle + angY) % 360;
zAngle = (zAngle + angZ) % 360;
transform.eulerAngles = Vector3(xAngle, yAngle, zAngle);
}
</pre>
The precise x, y and z angles are available at the variables xAngle, yAngle and zAngle.Sun, 25 Sep 2011 16:42:53 GMTaldonaletto