Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to teleport cinemachine virtual camera properly?

Discussion in 'Cinemachine' started by Darth_Biomech, Mar 15, 2020.

  1. Darth_Biomech

    Darth_Biomech

    Joined:
    Nov 28, 2019
    Posts:
    5
    I am trying to teleport the player from one place to another. Camera should follow up more or less seamlessly.
    This is how the cinemachine set up:

    This is the code for teleportation, inside the player's script:
    Code (CSharp):
    1.         public void TeleportMe(Vector3 coords)
    2.         {
    3.             platformerBrain.virtualCamera.OnTargetObjectWarped(transform, transform.position - coords);
    4.             transform.position = new Vector3(coords.x, coords.y, transform.position.z);
    5.         }
    and this is the result:

    Not only it looks ugly, it also sometimes breaks the 2d lighting asset. How can I fix away that rubberbanding effect?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    Reverse the order of the subtraction?
     
    Darth_Biomech likes this.
  3. Darth_Biomech

    Darth_Biomech

    Joined:
    Nov 28, 2019
    Posts:
    5
    It worked.
    I feel profoundly stupid now. XD
     
    Gregoryl likes this.
  4. Apollo11_1969

    Apollo11_1969

    Joined:
    Nov 20, 2018
    Posts:
    15
    Hi

    I'm developing my first game, and I've run into the same problem. This looks like it might be the solution that I need. How do you get the reference to "platformerBrain" in the example above?

    I don't have a good understanding of the classes relating to programming for Cinemachine. I've seen a class reference but I find it pretty impossible to find the classes I need. The tutorials in Unity Learn are helpful for using Cinemachine and they help in creating understanding about some of the underlying concepts but I haven't found any help in them for programming for Cinemachine.

    I suspect it might not make a difference, but just in case - my game is 3D.

    Thank you and kind regards

    Jeff
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
  6. Apollo11_1969

    Apollo11_1969

    Joined:
    Nov 20, 2018
    Posts:
    15
    Thank you

    Jeff
     
  7. Oliver0769

    Oliver0769

    Joined:
    Apr 28, 2021
    Posts:
    11
    Don't worry I have had similar problems and felt even dumber. :D