Tom Wor

Professional web developer and indie game creator. Passionate about autonomy for creative professionals, true ownership and permissionless technology.

Pushing Cinemachine Camera to Do a Hard Position Change With Ontargetobjectwarped

Oct 15, 2018 — 1 min read

While switching my camera system on Super Space Arcade from a classic camera rig to Cinemachine, I stumbled over an issue where the virtual camera would change its position smoothly, even though I set the transform to a new value. In my case, I need a hard reset of the camera position for the linear track being reset, to not run into overflow errors.

The way this can be achieved with Cinemachine I dug up somewhere in the forums, is

CinemachineComponentBase.OnTargetObjectWarped(Transform, Vector3)

The first parameter is the moving objects transform, the second is the transform offset. In my case, the code looks something like this

CinemachineVirtualCamera vcam = this.GetComponent<CinemachineVirtualCamera>();
vcam.OnTargetObjectWarped(playerTransform, new Vector3(0,0,-trackResetZ);
To Homepage