Search Unity

Question FreeLook camera: Get rid of transition to new position

Discussion in 'Cinemachine' started by theghostronaut, Apr 13, 2022.

  1. theghostronaut

    theghostronaut

    Joined:
    Jul 27, 2018
    Posts:
    41
    I‘m using a FreeLook, 3rd person camera.
    At a specific situation in my game, the player is teleported instantly to a new position. When this happens, my FreeLook camera does a weird transition (big sweeping motion starting above the player). How can I have my freelook camera instantly cut to that new position?
     
  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    To fix this, you can call this on your freelook:
    Code (CSharp):
    1. freelook.OnTargetObjectWarped(target, positionDelta);
     
    Gregoryl likes this.
  3. theghostronaut

    theghostronaut

    Joined:
    Jul 27, 2018
    Posts:
    41
    Thank you, could you elaborate on where / in what order to call this exactly? The way I'm doing it now does not change the behavior, the camera is still being transitioned through geometry to the new position instead of "warping" immediately:

    Code (CSharp):
    1. var newPosition = warpTarget.position;
    2. var movementDelta = newPosition - PlayerController.transform.position;
    3.      
    4. cameraManager.mainOrbitCam.OnTargetObjectWarped(warpTarget, movementDelta);
    5. PlayerController.transform.position = newPosition;
    -Edit-
    I got it working by looking through this thread. The solution to my problem was calling the following after the position change (instead of OnTargetObjectWarped):

    Code (CSharp):
    1.  cameraManager.mainOrbitCam.PreviousStateIsValid = false;
     
    Last edited: Apr 14, 2022