Search Unity

Target Group jerks camera when tweening/lerping a target's weight to and from zero

Discussion in 'Cinemachine' started by PvtPrivate, Jan 30, 2019.

  1. PvtPrivate

    PvtPrivate

    Joined:
    Jun 7, 2015
    Posts:
    2
    Tweening or lerping a target's weight from or to zero, while other existing targets have different weights, will make the target group "ignore" the higher weighted targets and seems to clamp all target's weight to 1.

    This is because CinemachineTargetGroup's weight calculation (WeightedMemberBounds) divides each target's weight (w) by the average weight (mAverageWeight) of the target group if the target's weight (w) is below the average weight (mAverageWeight). If the target's weight (w) is above or the same as the average weight (mAverageWeight) the target's weight (w) is clamped to 1.

    Code (CSharp):
    1. if (w < mAverageWeight) {
    2.     w = w / mAverageWeight;
    3. } else {
    4.     w = 1;
    5. }
    Thus if you add another target with a weight of nearly 0, say 0.002. The average weight will go down which could make nearly all target's weight to be clamped to 1.
    This could be avoided or "fixed" if we use the maximum weight of all the target instead of the average weight.

    This "fixes" the problem but it requires all existing target group weights to be adjusted or tweaked, as the weight distribution has changed. (i have to reduce the player's weight to 1.5 from 2 to have the same effect as before).



     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Thank you for this. Really interesting. Looks like a bug. We'll check it out and get back to you.
     
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Actually your fix of using the max instead of the average seems reasonable.