- Home /
Need to apply RotateAround to a Quaternion.Lerp
Can't find anything else around for this, nothing I've tried has worked and I feel like I'm missing something really simple. I need to apply RotateAround
to
child.transform.localRotation = Quaternion.Lerp(child.transform.localRotation, to.rotation, t);
child
is a gameobject and I need it to RotateAround
another gameobject called Player.
The answer depends on precise specifics of the situation and what you need, really. For example, you may think you need a rotation, but it may well turn out you need a translation or both.
This will rotate (in place) around an axis:
Quaternion src = child.transform.rotation;
Quaternion dst = src * Quaternion.AngleAxis( angle:15f , axis:Player.transform.up );
child.transform.rotation = Quaternion.Slerp( src , dst , t );
This will rotate object position around a point with an axis (orbit):
Vector3 pivot = Player.transform.position;
Vector3 axis = Player.transform.up;
Vector3 src = child.transform.position;
Vector3 dst = pivot + Quaternion.AngleAxis( 15f , axis ) * ( src - pivot );
child.transform.position = Vector3.Lerp( src , dst , t );
Sidenote: I calculate everything in world space, because I have no idea how your transform hierarchy looks like.
Thanks for the answer even though I was unspecific, I had the part where it would rotate to a point fine, but I needed the child object to rotate back to the 0,0,0 orientation. My issue is that when I had my player on the plane (named child cause i was trying a parent child thing with this issue earlier), when I press a key the plane rotates with the player as the pivot point on it, but when it returned to the default rotation it would use the default pivot in the centre. Tried to make a quick example in paint https://i.imgur.com/k1VRJI1.png When ever I would tilt the plane then tilt it back the plane would move up or down from its original position depending on where I was on the plane. The script i used for tilting is
if (Input.GetKey(KeyCode.W)) { t2 = 0.05f; if (!barrier.hit) { child.transform.RotateAround(player.transform.position, Vector3.left, t2); } }
Your answer
![](https://koobas.hobune.stream/wayback/20220613033347im_/https://answers.unity.com/themes/thub/images/avi.jpg)