# Resetting transform's original position and rotation after using transform.rotateAround

 0 `enter code here`I have written a script which tilts the player's model (independently of the player's transfrom around a point using) using transform.rotateAround().What's missing is that I want, at a certain point, to set back the model where it was in the beginning (but relative to the player's transform). I thought this was pretty simple but setting: ``````model.transform.rotation = Quaternion.Euler(...) model.transform.position = transform.position(...) + new Vector3(...) ``````is behaving strangely, any ideas on how to reset back the position after using transform.RotateAround() ?Help would be greatly appreciated, thanks in advance.===================================================== EditBelow I've pasted my code: ```private void HandleTilting() { // print(model.transform.localEulerAngles.x + ", " + model.transform.localEulerAngles.y + ", " + model.transform.localEulerAngles.z); //print(originalModPos); turn = currModelRotY - prevModelRotY; if (turn > 0 && model.transform.localEulerAngles.z < 10) model.transform.localRotation = Quaternion.Euler(model.transform.localRotation.x, model.transform.localRotation.y, 359); if (turn < 0 && model.transform.localEulerAngles.z > 350) model.transform.localRotation = Quaternion.Euler(model.transform.localRotation.x, model.transform.localRotation.y, 1); //right titling if (turn < 0) { rightAngle = 2 - ((2 * model.transform.localEulerAngles.z) / 40); model.transform.RotateAround(transform.position + new Vector3(0, 5, 0), transform.forward, rightAngle); } else if (turn > 0) { leftAngle = 2 - (2 * (360 - model.transform.localEulerAngles.z)) / 40; model.transform.RotateAround(transform.position + new Vector3(0, 5, 0), transform.forward, -leftAngle); } if (turn == 0 && model.transform.localEulerAngles.z = 0) { rightAngle = (2 * model.transform.localEulerAngles.z) / 40; model.transform.RotateAround(transform.position + new Vector3(0, 5, 0), transform.forward, -rightAngle); } else if (turn == 0 && model.transform.localEulerAngles.z >= 270 && model.transform.localEulerAngles.z It has to be refined but tilting left when the button is pressed and going smoothly back works perfectly, and so does vice versa but when combining them together ...well I know what the problem is I just need to set the local z rotation to 360 when tilting left and 0 when tilting right but for some reason the following code doesn't set the rotation if (turn > 0 && model.transform.localEulerAngles.z < 10) model.transform.localRotation = Quaternion.Euler(model.transform.localRotation.x, model.transform.localRotation.y, 359); if (turn < 0 && model.transform.localEulerAngles.z > 350) model.transform.localRotation = Quaternion.Euler(model.transform.localRotation.x, model.transform.localRotation.y, 1); ================Thanks for the swift reply btw. ``` more ▼ asked Sep 25 '11 at 04:29 PM jonathan.sant 16 ● 8 ● 8 ● 9 aldonaletto 41.3k ● 16 ● 42 ● 195 I edited my answer to include a possible solution for what you're trying to do - take a look at that. Sep 26 '11 at 01:26 AM aldonaletto add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 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": ```// 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); ```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: ```Character Pivot Model ```When banking to any side, just set the Pivot localEulerAngles like this: ``` Pivot.localEulerAngles = Vector3(0, 0, angle); ```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. 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. 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: ```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); } ```The precise x, y and z angles are available at the variables xAngle, yAngle and zAngle. more ▼ answered Sep 25 '11 at 04:42 PM aldonaletto 41.3k ● 16 ● 42 ● 195 I've edit the problem. Sep 25 '11 at 05:24 PM jonathan.sant thx this was awesome Oct 02 '11 at 01:50 PM jonathan.sant add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x2158
x1274
x87
x55
x3

asked: Sep 25 '11 at 04:29 PM

Seen: 3545 times

Last Updated: Oct 02 '11 at 01:50 PM