Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Person Camera Shifting Upon Animation

Discussion in 'Scripting' started by Kfollen, Jan 12, 2021.

  1. Kfollen

    Kfollen

    Joined:
    Nov 12, 2019
    Posts:
    37
    Hi All,

    I've created a third person camera script (and followed a few tutorials to see if I'm doing anything wrong). I had this working perfectly on a test character model which was just a cylinder. Now that I've imported my actual character model with animations, I noticed the camera is following each of the animations. This means when my character is in the idle position and moving his head, it also turns the camera. When I swing with the sword, the camera follows the sword. I'm not understanding how to fix this. I have created an empty cameraFollow as a child to the character, and then a cameraBase empty that holds the cameraFollow. The cameraBase has the camera script on it.

    I know the script itself is working, because I had used it prior and tried a few different tutorials to ensure I didn't mess anything up. However, it's tracking the animations no matter what I do and I can't find a solution. Ultimately I ended up using the script found here:


    As I thought this would fix my problem, but it still remains. Is it something within the animations themselves? I didn't make the character, so maybe there's something I don't know about.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,514
    First understand the things that drive your camera:

    - what drives its position
    - what drives its rotation

    One handy way is to run the game and dig around the scene while things are running.

    Once you understand that, refactor your setup so the animated portions of your character do not impact the camera.
     
  3. Kfollen

    Kfollen

    Joined:
    Nov 12, 2019
    Posts:
    37
    It's appearing like whenever I tried childing anything to the character, it's the whole character model - so the camera moves with it all. So if I put the camera follow object as the parent, it works when standing still, but upon movement the character runs away from the camera.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,514
    Could be that the animation is moving the character (root motion)

    If this is the case, then perhaps you want to make a proxy object where your camera is now, then a script that drives ONLY the position to that point, but gets the rotation from something else.

    If it is NOT root motion driving the player forward, you can bypass the animated hierarchy and hang the camera outside of it:

    Code (csharp):
    1. PlayerPrefab
    2.    CameraOffsetter
    3.        ActualCamera
    4.    PlayerAnimatedAndAllHisSubObjectsEtc
    But that only works assuming your motion is on a script that is ON the PlayerPrefab, or can be moved to it.
     
  5. Kfollen

    Kfollen

    Joined:
    Nov 12, 2019
    Posts:
    37
    I think the animation is moving the character. The other person working on the project created and rigged the character in Blender, but used Mixamo for the animations. I tried creating the hierarchy as you listed above, but getting the same results. Whenever the char turns his head in the idle animation it pans the camera to the left and right.
     
  6. Kfollen

    Kfollen

    Joined:
    Nov 12, 2019
    Posts:
    37
    Update: I've got the camera to stop following the player's animation. It follows my player properly, but my player and camera are moving independent of each other. When I turn the mouse, the camera moves a bit, but the player can turn 180 so that he's facing the camera. I am trying to keep the camera behind the player at all times, so you can only ever see the player's back.

    Edit:

    Using
    Code (CSharp):
    1. transform.forward = player.transform.forward;
    or
    Using
    Code (CSharp):
    1. transform.LookAt(player);
    Cause the camera to shake again with the animations :(
     
    Last edited: Jan 13, 2021