Search Unity

Setting Player Position/Rotation getting messed up when using Cinemachine.

Discussion in 'Cinemachine' started by MonkeyZero, Dec 31, 2018.

  1. MonkeyZero

    MonkeyZero

    Joined:
    Feb 20, 2013
    Posts:
    37
    So recently, I have been fooling around with Making a Player SpawnMarker system Simulare to the kind that Bethesda Uses for their games like Skyrim and Fallout 4 (Vault76 is trash so let's just forget that exist for now.) and to accomplish this, I had to make a UI Event System into a Singleton GameMaster object to store a couple of variables between scenes and create a SpawnMarker GameObject that Acts as an address the player is to be sent to when they arrive.

    The SpawnMarker when Awake() is called grabs the TargetAddress from the GameMaster Instance, Compares it to its own SpawnAddress.

    If the two match, then the SpawnMarker grabs the Player and is supposed to move the GameObject to itself then rotates the player to match the SpawnMarker's Rotation using:

    Code (CSharp):
    1. PlayerObject.transform.SetPositionAndRotation(this.transform.position, this.transform.rotation);
    While writing the code, I was just using the Standard Assets (From the Asset Store) FirstPersonController to have something to work with while I developed and a base to build on as I progress.

    But this is pretty basic stuff and not the best solution for my needs. but it's all I can afford at the moment.

    I also have plans on using Fungus for all my narrative needs and for that, I needed a Camera Solution that allows me to detach the MainCamera from the Player Controller. For this, I selected Cinemachine as it been the big deal for a while now.

    After Playing with it for a few hours, I converted the Main Camera in the Player Controller into a Depth Only WeaponLayer Camera, Killed it's Audio Listener. made a Virtual Camera a child of the Player Camera, Set a basic LookAt Target Empty as a child of the Player Camera. and told the Player Virtual Camera to Follow Player Camera while Targeting the LookAt Sibling.

    This is where the whole Spawn Marker System breaks, as for some reason Cinemachine Breaks the SpawnMarker by not rotating the player to the Markers Rotation. Heck, it barely even squeaks out a move of the Player at the Markers Transform position at times.

    It's as if it does move the Player Controller. Rotates it, then once it's done, Rotates it back to the original rotation.

    This is not good for a bread and butter thing like Positioning and rotating the player controller.

    At first, I thought it was a Unity Error, or a Standard Asset being out of date Error. But now I can see it's a Cinemachine or User Error.

    Is there something I am not doing that can make this Jumping back to the Original Rotation after the new Rotation is set? Or is this a Cinemachine being broke AF code and should find a new solution for my Camera needs?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,730
    The description of your setup sounds strange. The virtual camera is a child of the Player Camera? And it follows the Player Camera? That doesn't make sense, and will no doubt give you unwanted results.

    You need to have the main camera as a root object, with a CinemachineBrain on it. The virtual cameras are separate game objects, not parented to the camera. What the brain does is to position itself to match the active virtual camera. That virtual camera will animate its own transform according to the components you configure in the Aim and Body sections, and the LookAt/Follow targets.