Trouble with teleporting and damping

Hi there!

I’ve been trying to teleport my player in order to use a world streaming technique for my 3D game and I’m having issues getting my vcam to behave the way I want.

I basically want the teleport to be seamless, so that the player doesn’t notice they are being re-centered. The issue, is when I do this the camera has a bit of a bounce as it readjusts. I’ve looked at several threads and have been unable to correct this

Here is my camera’s current behavior:

7648486--953548--Camera Teleport Damping.gif

It’s not a huge thing, but that little bounce as it readjusts after the player get’s teleported (after hitting the white line) is jarring and noticeable. I suspect the reason I can’t find a solution online is because lots of the threads I found were about fading to black and then fading back in, so this would likely not even be noticeable.

With the player moving however, and no fade, it’s an issue.

Here is what I want:

7648486--953554--Camera Teleport No Damping.gif

It’s perfect! I got this result by turning the vcam’s 3rd person follow body to have 0s for the damping vector.

Problem is, I want the damping for the actual camera controls. I tried changing the damping to zero, disabling the camera, moving the player, enabling the camera, and then changing the damping back in the teleport method but no luck, I guess it might be too quick of a change for the camera to keep up, not sure how quickly it updates it’s values.

I would really appreciate some help with this! I absolutely want to use camera damping in my game and I’d hate to have to remove it :frowning:

If you need any more info about my settings or code feel free to ask and I can update the post :slight_smile:

Call vcam.OnTargetObjectWarped() when the player teleports, and it will be seamless even with damping.

2 Likes

Hi and thanks for the reply!

I’m already doing that actually, I’m using the following code:

var delta = newPosition - transform.position;
transform.localPosition = newPosition;
thirdPersonCam.OnTargetObjectWarped(transform, delta);

Where newPosition is the player’s new position and transform.position is the player’s current position. The follow transform for the camera is a child of the player transform.

Not sure if I’m using it wrong, but it honestly doesn’t seem to be doing much, I can’t tell a difference when I turn it on or off.

The line that does seem to make a difference is:

thirdPersonCam.PreviousStateIsValid = false;

This makes it so the camera snaps to the player’s new position rather than lerp to it.

But the issue is that even after the camera snaps to the position, it snaps to its default state, and when the player continues to run as shown in the gif, it does it’s slight zoom out.

I have it where the camera kind of slightly zooms out as the player moves. I believe that’s from this section of the vcam:

7651399--954010--upload_2021-11-12_11-19-46.png

The more delta I do, the more the zoom out as the target moves, but the problem is that the target was already moving before the warp, and the camera kind of resets after the warp rather than continue where it was. My first person camera, which doesn’t do that, works perfectly, and as I mentioned, when I turn down the delta to zero, it works as I want, I just really like the delta so I’m trying to see if I can make it work with it.

The transform that you pass to OnTargetObjectWarped() must the transform of the actual target of the vcam - not a child or parent of the target. That is probably why you are seeing no effect.

Note: make sure that you are using the latest version of CM. Some earlier versions had a bug causing 3rdPersonFollow not to fully respect OnTargetObjectWarped.

1 Like

That makes sense, I tried changing the target of the warp to be the followTarget and had no luck though, still getting the exact same result though.

Maybe my delta is wrong? Though I’m not sure how I would fix it, I tried a few different things and they all produced the same result.

Currently I’m using version Version 2.6.10 - August 24, 2021.

It looks like there is an update available so I’ll have to try that later.

Your delta calculation looks right to me.
Try upgrading CM and let me know how it goes.

Ok, I updated to the latest CM version, still having same behaviour.

Here is my entire teleport method now that I cleaned it up:

public void TeleportPlayerTest(Vector3 newPlayerPosition)
        {  
            // followTransform is the vcas follow and look at target
            // it's also a child of the player's transform
            Vector3 delta = newPlayerPosition - followTransform.position;

            // this sets the player's transform to the new position
            transform.localPosition = newPlayerPosition;
           
            // the booleans are for testing
            if (objectWarped)
            {
                thirdPersonCam.OnTargetObjectWarped(followTransform, newPlayerPosition);
            }          

            if (ignorePreviousState)
            {
                thirdPersonCam.PreviousStateIsValid = false;
                firstPersonCam.PreviousStateIsValid = false;
            }

        }

The behavior still looks exactly like the first gif unless I zero out the damping on the vcam’s body :frowning:

Without more context, I can’t really say what you’re doing wrong. I can say that it works for me when I try it. I made a quick test with a 3rdPersonFollow vcam and a player that moves and warps its position from time to time. It works as expected: the camera warps seamlessly along with the player. I’ve attached my test so you can see it. Just import the package and play the WarpTest scene.

7661431–956161–WarpTest.unitypackage (133 KB)

I’m getting an error with the line:

CinemachineCore.Instance.OnTargetObjectWarped(transform, pos - transform.position);

On the warper class. It says it does not contain a definition for OnTargetObjectWarped

Any ideas?

Sounds like you don’t have the latest CM. What version do you have?

I made a sample project to test it, it’s version 2.6.11 which I think is the latest.

I did end up fixing it by just making a reference in the inspector to the vcam. Not sure why the CinemachineCore.Instance wasn’t working though.

You’re right that the transition does seem to be seamless here. I’m gonna look through my code some more and see if I can spot where the issue might be.

The latest verified CM is 2.8.2.

7661707--956203--upload_2021-11-16_9-19-48.png

CinemachineCore.Instance.OnTargetObjectWarped is a convenience method that was added so that you don’t need to know which vcams are targeting your player - it iterates through all of them and warps the ones whose target matches the one passed in.

Thanks for the tip and yeah I guess I didn’t check the other version section so now I’m all up to date!

It seems to be working now. Here is my current working code, which was cleaned up and is almost the same as yours:

public void TeleportPlayer(Vector3 newPosition)
        {
            Vector3 delta = newPosition - transform.localPosition;

            thirdPersonCam.OnTargetObjectWarped(followTransform, delta);
            firstPersonCam.OnTargetObjectWarped(followTransform, delta);

            transform.localPosition = newPosition;
        }

I’m almost sure I had this exact code at one point as I was trying things so I’m wondering if it was the CM update that fixed it.

It’s working great now in both 3rd and 1st person so that’s nice! I’ll have to experiment with the CinemachineCore.Instance.OnTargetObjectWarped and see if it suits me since I’m using 2 cameras, sounds like it could be convenient.

Thanks a ton for the help!

2 Likes