0

I am rotating my object in all 3 axis with Quaternion. Is there a possibility to multiply it with a given speed?

I am using Quaternion.Inverse in my example instead of Quaternion.Euler, would it still be possible to do arithmetic on it?

private Quaternion initialObjectRotation;
private Quaternion initialControllerRotation;
private bool offset;
public GameObject obj2;

public void Update() {

        if (offsetSet == false) {
            initialObjectRotation = transform.rotation;
            initialControllerRotation = obj2.transform.rotation;
            offsetSet = true;
        }

         Quaternion controllerAngularDifference = initialControllerRotation * Quaternion.Inverse (obj2.transform.rotation);
         transform.rotation = controllerAngularDifference * initialObjectRotation;
    }
Nijako
  • 15
  • 4
  • 1
    what exactly do you expect the speed multiplier to influence? Does it modify the target rotation? Or are you actually rather speaking off e.g. using [`Quaternion.RotateTowards`](https://docs.unity3d.com/ScriptReference/Quaternion.RotateTowards.html) or [`Quaternion.Slerp`](https://docs.unity3d.com/ScriptReference/Quaternion.Slerp.html) in order to smoothly rotate towards the given target rotation? Like what exactly is the expected behavior? – derHugo May 23 '23 at 12:19
  • @derHugo yes exactly I want my transform.rotation to smoothly reach the destination. Basically if I use Quaternion.Euler (0, this.transform.eulerAngles.y * speed, 0); here with Euler I can easily multiply rotation with speed, I want to achieve the same thing in my code. – Nijako May 23 '23 at 12:25
  • @derHugo I would also like to know if I can modify target rotation with speed. – Nijako May 23 '23 at 12:30
  • `Quaternion.Euler (0, this.transform.eulerAngles.y * speed, 0);` alone doesn't do anything ... the question is how exactly you assign this back to a transform and as mentioned `RotateTowards` and `Slerp` both allow to smoothly move ... the first with a defined constant speed (angle/second) the other with a more dynamic interpolation factor between the two given values (can feel smoother if used right) .. you can also implement [something similar to `Vetcor3.SmoothDamp` for Quaternions](https://forum.unity.com/threads/quaternion-smoothdamp.793533/) – derHugo May 23 '23 at 12:33

0 Answers0