Search Unity

How to slerp Quaternion with different damping for each angle ?

Discussion in 'Getting Started' started by ShinigamiUzi, Dec 3, 2018.

  1. ShinigamiUzi

    ShinigamiUzi

    Joined:
    Sep 5, 2017
    Posts:
    54
    Code (CSharp):
    1. transform.rotation = Quaternion.Slerp(transform.rotation, player.transform.rotation, Time.deltaTime * currentDamp);
    This example code will slerp the object full angles to the player angles at some rate,, suppose I wanted to add more damping only on Y axis, how would I do it?

    thanks
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    First of all, this is Lerp abuse. Please stop it. It may happen to work for you on your machine in the current version of your code under certain circumstances, but it will bite you in the rear sooner or later.

    Secondly, if you really want rotation around the Y axis to be different from rotation around X and Z, then you can't do this with quaternions. You should keep track of your three rotations (yaw/pitch/roll) separately, and move them (using Mathf.MoveTowardsAngle or some damped version as appropriate) separately.
     
  3. ShinigamiUzi

    ShinigamiUzi

    Joined:
    Sep 5, 2017
    Posts:
    54
    To be honest with you, I found that Quaternion.Lerp resulted in a much smoother rotation than that of rotateTowards, what damping method you recommend
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    That's because RotateTowards, itself, doesn't do any damping. You'd need to do that by changing the final parameter (the max rotation) over time.

    But hey, it's a free country. Dig your own hole if you like. :p
     
  5. ShinigamiUzi

    ShinigamiUzi

    Joined:
    Sep 5, 2017
    Posts:
    54
    did you just assume my country
     
    turelmert_unity likes this.