Search Unity

Bug OnTargetObjectWarped doesn't work with body set to 3rd Person Follow

Discussion in 'Cinemachine' started by FrankSchmutz, Jul 21, 2021.

  1. FrankSchmutz

    FrankSchmutz

    Joined:
    Apr 18, 2020
    Posts:
    4
    Hi,

    I have a simple virtual camera with a follow target. Teleporting the target back to the origin and calling OnTargetObjectWarped works with every virtual camera setup I've tried except for 3rd Person Follow.

    Unity version: 2020.3.14f1
    Cinemachine version: 2.6.5
    Here is a minimal script attached to the virtual camera target that can be used to reproduce the bug.

    Code (CSharp):
    1. public class CameraTPTest : MonoBehaviour
    2. {
    3.     public CinemachineVirtualCamera VCam;
    4.     public float Speed = 10f;
    5.  
    6.     private void LateUpdate()
    7.     {
    8.         transform.position = transform.position + (Vector3.forward * Speed * Time.deltaTime);
    9.         if (transform.position.magnitude > 20f)
    10.         {
    11.             Vector3 delta = -transform.position;
    12.             transform.position = Vector3.zero;
    13.             VCam.OnTargetObjectWarped(transform, delta);
    14.         }
    15.     }
    16. }
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,723
    Thank you, you are right!
    We will fix it for the next CM release.
     
  3. FrankSchmutz

    FrankSchmutz

    Joined:
    Apr 18, 2020
    Posts:
    4
    I tested the same setup with cinemachine 2.6.11 and 2.7.9 and the bug is still present.
    Any estimate when this might be fixed?

    Thanks
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,723
    It's fixed in CM 2.6.11, and 2.7.9, and 2.8.2.

    If you're still seeing issues, it might be because of your script and your vcam setup. You have to call OnTargetObjectWarped with the actual vcam target, not its parent. With a 3rdPersonFollow, this target is often a child of the player. Perhaps that is what you are seeing.

    I modified your script to do that:

    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. public class CameraTPTest : MonoBehaviour
    5. {
    6.     public CinemachineVirtualCamera VCam;
    7.     public Transform VcamTarget;
    8.  
    9.     public float Speed = 10f;
    10.     private void LateUpdate()
    11.     {
    12.         transform.position = transform.position + (Vector3.forward * Speed * Time.deltaTime);
    13.         if (transform.position.magnitude > 20f)
    14.         {
    15.             Vector3 delta = -transform.position;
    16.             transform.position += delta;
    17.             VCam.OnTargetObjectWarped(VcamTarget, delta);
    18.         }
    19.     }
    20. }
     
    Last edited: Nov 4, 2021
  5. FrankSchmutz

    FrankSchmutz

    Joined:
    Apr 18, 2020
    Posts:
    4
    Sorry my bad I completely overlooked that. It's working fine now.
    Thanks for the quick reply
     
    Gregoryl likes this.