Search Unity

Combining two Quaternion.Slerp functions

Discussion in 'Scripting' started by flowb, Dec 19, 2013.

  1. flowb

    flowb

    Joined:
    Dec 19, 2012
    Posts:
    5
    Hey all,

    after hours of trying i cant seem to get to the point of this problem. Im trying to combine two 45° rotations around the X- and Z-Axes with Quaternions and want the speed of the Orientation relate to the Mousemovement. What i get here is the right direction of the Rotation but it is superfast and never ends.

    Code (csharp):
    1.  
    2. RightRot = Quaternion.Slerp(transform.localRotation,TargetRotationRight, speed*Time.deltaTime);
    3. TopRot = Quaternion.Slerp(transform.localRotation,TargetRotationTop, speed*Time.deltaTime);
    4. transform.localRotation = RightRot*TopRot;
    5.  
    Deleting one Factor of the Product results in normal expected behaviour. Putting the Quaternionproduct in a Slerpfunction itself also works. Why doesnt this code do the trick then?

    Thanks All! I really dont get it.
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Sounds like it working as expected, you are just not expecting the right thing
    When you slerp from MyRotation to TargetRotation, eventually MyRotation becomes TargetRotation. But you have 2 Targets
    So you say adjust MyRotation towards Target1, then you say adjust MyRotation towards Target2. The result being that it would never reach target 1.
    But then next frame frame you try again to move it back towards Target1, and again, etc

    If you have a Right and Top value for rotation, is it better for you to use Quaternion.Euler( targetX, targetY, someZ) ?, then you can Lerp the values of those independantly.
     
  3. flowb

    flowb

    Joined:
    Dec 19, 2012
    Posts:
    5
    Thank you very much, changing transform.localrotation in the Slerp functions to two seperate Quaternions did solve my Problem! I really thought using the Slerp function would be the easier way to got. Next time ill try it manually.