- Home /
2D Cinemachine with Lookahead time respawn problem
I am working on a 2D platformer. In a level I have some checkpoints so that if you take one of them, when you die the player gameObject gets moved to the last checkpoint location. That is done this way:
private void death() { rb.velocity = Vector2.zero; transform.position = respawnPos; }
I also have a 2d cinemachine follow cam set up to follow the player. I gave the camera '0.2f' of lookahead time.
The problem is whenever I die and the player position is changed my camera moves too much because it's applying the lookahead time, then it snaps back to the player (it behaves like the instant change of position of the player is a movement). I also added that on death the rigidbody.velocity goes to zero hoping this would fix my problem but it doesn't.
Is there a simple way to fix this issue? [please solution in c#]
(I don't know much of how cinemachine works, I just watched some basic tutorials)
Answer by caogtaa · Apr 23, 2020 at 08:07 AM
I had the same problem and it was solved.
When your player gameObject respawn, get CinemachineFramingTransposer
component of your virtual camera:
_framingTransposer = _virtualCamera.GetCinemachineComponent<CinemachineFramingTransposer>();
Then call this function:
_framingTransposer.OnTargetObjectWarped(_virtualCamera.Follow, delta);
The parameter delta
should be respawn_position - die_position
in your case.
Answer by JonathanDC · Apr 22, 2019 at 03:20 PM
I'm having the EXACT same problem. Haven't found a solution yet. Let me know if you find anything.
Answer by dato818 · Feb 22, 2020 at 10:04 AM
Late answer but for others that have the same problem.
In respawn code, deactivate the respawned object and then turn it on.