Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Vehicle Feel Masterclass: Balancing Arcade Accessibility with Simulation Depth

Discussion in 'Scripting' started by nguenphonghoangson, Apr 13, 2024.

  1. nguenphonghoangson


    Apr 4, 2023
    Hi, I want to make a vehicle camera based on the image above. Where should I start to calculate the rotation angle and speed to be as smooth as possible?
  2. Kurt-Dekker


    Mar 16, 2013
    Camera stuff is pretty tricky... you may wish to consider using Cinemachine from the Unity Package Manager.

    There's even a dedicated forum:

    If you absolutely insist on reinventing the wheel and making your own camera controller, do not fiddle with camera rotation.

    The simplest way to do it is to think in terms of two Vector3 points in space: where the camera is LOCATED and where the camera is LOOKING.

    Code (csharp):
    1. private Vector3 WhereMyCameraIsLocated;
    2. private Vector3 WhatMyCameraIsLookingAt;
    4. void LateUpdate()
    5. {
    6.   cam.transform.position = WhereMyCameraIsLocated;
    7.   cam.transform.LookAt( WhatMyCameraIsLookingAt);
    8. }
    Then you just need to update the above two points based on your GameObjects, no need to fiddle with rotations. As long as you move those positions smoothly, the camera will be nice and smooth as well, both positionally and rotationally.