Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Camera position changing

Discussion in 'Cinemachine' started by Mangonels, Sep 26, 2018.

  1. Mangonels

    Mangonels

    Joined:
    May 8, 2018
    Posts:
    20
    So I want to programatically change the position of a cinemachine virtual camera I have referenced, which may, or may not be active. I've tried the classic transform.position fiddling, however, this doesn't seem to be possible. Let me know if there's a propper or less propper way to do this.

    Edit: By active I mean the active cinemachine camera, not an unity active/inactive cinemachine camera in scene.
     
    Last edited: Sep 26, 2018
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,742
    If the vcam has anything other than "Do Nothing" in the Body section, then it is setting its own position procedurally, every frame, based on the Follow target and other inputs as the case may be. If you want to position the vcam yourself, put Do Nothing in the Body, but then it won't ever try to move on its own.

    Maybe you can shed a little more light on what you're trying to accomplish?
     
  3. Mangonels

    Mangonels

    Joined:
    May 8, 2018
    Posts:
    20
    That could be good enough. I was really just wondering if I could change the coordinates, but since the position is being forced every frame I'm guessing your method is a good idea if I ever encounter such necessity again.
    Not really attempting to do this at the moment, but I've had issues in the past with a racing game I made, where the car respawned with the same camera being active, and the player had to wait for the camera to get to the car, your solution helps in case I have to do something similar again, which I imagine I will.

    Thanks a lot :)
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,742
    Actually, there is a special API to handle this situation: vcam.OnTargetObjectWarped().
    Call this when you warp the follow target and you want the vcam to warp along with it.
     
    Mangonels likes this.