Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Silly question.. how to animate first person

Discussion in 'Animation' started by DavidVoss96, Jun 25, 2020.

  1. DavidVoss96

    DavidVoss96

    Joined:
    Sep 19, 2013
    Posts:
    13
    This is going to sound pretty ridiculous, but I've been developing games on and off for 3 years, but I've never once touched animation unless it was something premade, such as third person controllers which already come animated, and these were only for traversing worlds I made. In this case I want to animate first person, specifically arms/hands.

    I don't want anything combat based, not even close, however I'd love to be able to make animations like those present in Firewatch, such as jumping over logs, holding a torch or picking something up. I'm just completely unsure how I'd do that because obviously whilst animating the hands, I'd also have to animate the camera when it comes to creating a bending down effect, jumping effect etc. Is there anywhere you guys could point me?

    Thanks
     
  2. mattSydney

    mattSydney

    Joined:
    Nov 10, 2011
    Posts:
    171
    Thats not a stupid question! Like many things there are lots of ways of doing this. A few ways that come to mind are:

    Quickest to experiment would be to take an existing 3rd person animation and model and move the camera to the head "bone" of the model just outside the head so the camera doesn't clip the head to see how the animations look from an FPS view and give you some ideas going forward.

    One way if you want to do it inside Unity is to use the "arms" as part of rigged model and animate the camera separately.

    So lets say you want to pick up a torch. I would create an animation for the hands picking up the torch, also animating the camera rotating to look down at the hands.

    In the game script it would be something like this...

    1 )Use regular FPS controller you have made for your game.
    2) When you trigger a torch pick-up animation.
    3) Switch off the player controls for the FPS controller for the user so (so the camera is no longer controlled via the FPS script) eg canControl = false
    4) switch on your camera and hands animation torch animation.
    Once the animation as finished, reactive FPS controls and continue

    Another example for a jump might be you want the camera to look down when the player presses jump. Again you could deactivate the FPS script during the "jump" sequence, activate your "camera looks down" animation, then once that jump sequence is played allow user to have control.

    This might help


    And I always use this for animation
    https://assetstore.unity.com/packages/tools/animation/dotween-hotween-v2-27676

    Here is an example of a script where I fake FPS controls for simplicity. But when the player presses space it stops the FPS and controls and runs an animation where the camera... waits for 1 second, then looks down and up before resuming FPS controls. PS it requires the free library Dotween https://assetstore.unity.com/packages/tools/animation/dotween-hotween-v2-27676

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using DG.Tweening;
    5.  
    6. public class FPS : MonoBehaviour
    7. {
    8.     public bool canControlFPS;
    9.     public bool lookDownPressed;
    10.     public bool isPlayingLookDownAnimation;
    11.    
    12.     // Start is called before the first frame update
    13.     void Start()
    14.     {
    15.         // put this on a camera
    16.     }
    17.  
    18.     // Update is called once per frame
    19.     void Update()
    20.     {
    21.  
    22.         if (isPlayingLookDownAnimation)
    23.             return;
    24.         if(Input.GetKeyDown(KeyCode.Space))
    25.         {
    26.             LookDownAtGround();
    27.         }
    28.  
    29.         FPSStuff();
    30.  
    31.     }
    32.  
    33.     void FPSStuff()
    34.     {
    35.         // loop that controls all out fps things such as user control and camera looking
    36.         transform.Translate(Vector3.forward * 0.01f);
    37.     }
    38.  
    39.     void LookDownAtGround()
    40.     {
    41.         isPlayingLookDownAnimation = true;
    42.         Sequence mySequence = DOTween.Sequence();
    43.         mySequence.Append(camera.transform.DORotate(new Vector3(45, 0, 0), 1)).SetDelay(2)
    44.           .Append(camera.transform.DORotate(new Vector3(-45, 0, 0), 2))
    45.           .Append(camera.transform.DORotate(new Vector3(0, 0, 0), 2))
    46.           .OnComplete(()=> isPlayingLookDownAnimation = false);
    47.        
    48.     }
    49. }
    50.  
     
    nathuyen likes this.