cinemachine 2d look-ahead problem in respawn
Hello! This is my first time posting here, so excuse any inexperience.
I am using Cinemachine 2D for a platformer. When I respawn, the camera seems to be offset in the direction you were moving previously. This only happens when the look-ahead time is greater than zero. Moving after respawning will slowly move the camera back into place.
Link to video in case you are wondering
Code for respawn (other is the target of the camera, being ran in a seperate script):
other.transform.position = _respawnPoint.position;
What I have tried
Disabling and re-enabling the cinemachine component on the main camera
Disabling and re-enabling the player
Cheating the way by slightly moving forward works slightly as look-ahead seems to work over time. Therefore making it not noticeable isn't possible
It is possible that there is no solution. Thank you in advance!
I haven't found a solution, I just decided to get rid of that feature, unfortunately.
Answer by kenleim2008 · Jun 28, 2020 at 02:53 PM
@Adriatogi I fixed it for now by disabling the Vcam, setting its transform and the player to the respawn location, waiting for 0.1s, then re-enabling the Vcam. I put that function in an IEnumerator. I haven't done any extensive testing but it works for now.
I took a break to learn some more Unity and then decided to come back to the problem to see if I could fix it.
Turns out I just had to disable and re-enable the CinemachineVirtualCamera component on the cine$$anonymous$$achine camera object ins$$anonymous$$d of the mainCamera object
Came back to comment the solution and @ you, but you had already done it hahaha
Answer by Adriatogi · Jul 06, 2020 at 08:10 AM
@kenleim2008 In case anyone else needs the answer in other terms:
Disable and re-enable the CinemachineVirtualCamera component on the cineMachine camera object instead of the mainCamera object.
Disable CM_Camera CinemachineVirtualCamera component
Move player
Make it wait some time with a yield return new WaitForSeconds inside a IEnumerator function
Enable CM_Camera CinemachineVirtualCamera component
Your answer
Follow this Question
Related Questions
If player hits certain X value in opposition to Camera, shift camera question. 0 Answers
C# Script On Camera Hides Player? 1 Answer
2D movement with gravity shifting 0 Answers
Trying to make a 2D Panning Camera 0 Answers
CS1216 error 0 Answers