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.

Top Down Cinemachine Camera

Discussion in 'Cinemachine' started by unity_TkvnlsDCpw-owg, Dec 2, 2021.

  1. unity_TkvnlsDCpw-owg

    unity_TkvnlsDCpw-owg

    Joined:
    Jul 16, 2020
    Posts:
    13
    I am trying to make a Top Down 2D car game. The Cinemachine is following the car. I want the camera to always face the Y direction of the car. So if the car turns on the right side camera also turns right. However when I turn the car the camera doesnt turn according to rotation of the car.
    Is there anyway I can implement it ? Thanks for the help
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    6,079
    Can you show an image of what you're trying to do, and also an image of your vcam inspector?
     
  3. unity_TkvnlsDCpw-owg

    unity_TkvnlsDCpw-owg

    Joined:
    Jul 16, 2020
    Posts:
    13
    Thanks.. The car is moving on Transform.up .. when it turns in the right direction, Cinemachine camera just moves sideways.. it doesnt rotate according to the transform.up of the car.... so when the car turns it appears the car is moving sideways not vertically...

    upload_2021-12-2_22-8-28.png
     
  4. unity_TkvnlsDCpw-owg

    unity_TkvnlsDCpw-owg

    Joined:
    Jul 16, 2020
    Posts:
    13

    PLs find the prototype game video on vimeo link above. This is how the camera moves when I make it a child of the car. I want to achieve similar results with cinemachine camera but without these jitters. I am unable to rotate the camera when the car turns
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    6,079
    If this is the case, then you can make a vcam with Transposer in the Body and Composer in the Aim. In the Transposer, set the Binding Mode to Lock To Target.
     
  6. unity_TkvnlsDCpw-owg

    unity_TkvnlsDCpw-owg

    Joined:
    Jul 16, 2020
    Posts:
    13
    Thanks a lot for the help. I will try it this way
     
  7. unity_TkvnlsDCpw-owg

    unity_TkvnlsDCpw-owg

    Joined:
    Jul 16, 2020
    Posts:
    13
    The problem I am facing is when the car makes small left, right turns it should not rotate .. but when the car makes a large turn to right,left , the camera should also rotate ... I tried it with Dead Zone.. but i am not successful..
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    6,079
    In that case, I would recommend going back to the FramingTransposer.

    To implement the camera turning, you will need a custom script that monitors the car's forward direction. When the car's angle is such that you want to turn the camera, then move the vcam's rotation towards the desired one. If you move it some percentage of the remaining difference every frame (for example, if you need to move it 90 degrees, then move it 45, if you need to move it 45 degrees then move it 22.5, etc), then you will have a nice damped movement.
     
  9. unity_TkvnlsDCpw-owg

    unity_TkvnlsDCpw-owg

    Joined:
    Jul 16, 2020
    Posts:
    13
    Thanks a lot Gregoryl for all the help.. I will try it with a script with the angles ..this is the script i wrote based on position.. the jitters are gone but havent solved the camera changing its angle when the car turns issue

    public class CameraFollow : MonoBehaviour
    {
    public Transform playerCar;
    public float boundX = 0.15f;

    void Update()
    {
    Vector3 delta = Vector3.zero;

    float deltaX = playerCar.position.x - transform.position.x;
    if (deltaX > boundX || deltaX < -boundX)
    {
    if (transform.position.x < playerCar.position.x)
    {
    delta.x = deltaX - boundX;
    }
    else
    {
    delta.x = deltaX + boundX;
    }
    }

    transform.position += new Vector3(delta.x, 0, 0);


    }
     
unityunity