Search Unity

3th person camera

Discussion in 'Cinemachine' started by Plnda, Apr 19, 2021.

  1. Plnda

    Plnda

    Joined:
    Nov 23, 2016
    Posts:
    14
    Hi all, i took the Cinemachine 3th person example as a base. And would like to have the movement like Division 2 where you can circle around you character when you are idle and moves the character will move towards the camera direction.

    This works great thanks to the example Unity provided. The only problem im having now is that the character will immidately snap towards the camera angle instead of rotating the character first and then move.

    How would i solve this. Since the follow target of the cinemachine is assigned to empty gameobject inside my player so when i move the rigidbody the follow cam wil rotate. if i rotate the `targetTransform` it will also affect the camera. Anyone got a clue on how to achieve the look i want?

    https://gist.github.com/Plnda/87a81b965cee0e322b31f15cb0553689
     
  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Could you provide more details on what you'd like to achieve?

    You mean this:



    Could you clarify this?
     
  3. Plnda

    Plnda

    Joined:
    Nov 23, 2016
    Posts:
    14
    (Timestamped t=216 or 3:34) (Can't post timestamped videos :() You can clearly see that the character snaps towards the camera forward instead of rotating it nicely towards that position. How can i achieve that with the above setup?
     
  4. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    I watched a couple of division 2 gameplay videos. I think, I understand what you need. Correct me if not.

    You want to rotate the camera, but only rotate the player slowly towards the camera forward. Something like how we damp our cameras when you move or rotate around.

    You can do this damping with a script like this. Attach this script to the player-mesh and set the two public parameters in the inspector. The vcam should not depend on the transform of the player-mesh, meaning it should not have the player-mesh (or a child transform) as follow or rotate target.
    Code (CSharp):
    1. using Cinemachine.Utility;
    2. using UnityEngine;
    3.  
    4. public class RotateTowardForwardSmoothly : MonoBehaviour
    5. {
    6.     public Transform TargetTransform;
    7.     public float Damping;
    8.  
    9.     void Update()
    10.     {
    11.         Transform myTransform = transform;
    12.  
    13.         float deltaAngle = TargetTransform.rotation.eulerAngles.y - myTransform.rotation.eulerAngles.y;
    14.         float dampedDeltaAngle = Damper.Damp(deltaAngle, Damping, Time.deltaTime);
    15.         myTransform.Rotate(Vector3.up, dampedDeltaAngle);
    16.     }
    17. }
     
    Plnda and Gregoryl like this.
  5. Plnda

    Plnda

    Joined:
    Nov 23, 2016
    Posts:
    14
    Thank you for your reply, i fixed i using a similar approach thank you for your information and time!