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

Camera Tilt While Turning

Discussion in 'Scripting' started by GrayWoolsey, Jun 26, 2020.

  1. GrayWoolsey

    GrayWoolsey

    Joined:
    Apr 20, 2018
    Posts:
    27
    So I recently played a game that when you would turn your camera would subtly swivel left and right depending on what direction you turn in. I really appreciated the effect and wanted to emulate it in my own project. However, I'm a beginner and still have a lot to learn so I'm trying to figure out how to do this smoothly. So far I have a rudimentary method in but it's horrible jittery as I'm just setting the angle of the camera instantly. How would I take this and make it smooth, happening over time?

    Code (CSharp):
    1. //Camera Tilt While Turning
    2. if (Input.GetAxis("Mouse X") < 0)
    3.           playerCamera.transform.Rotate(0, 0, 2.5F, Space.Self);
    4. else if (Input.GetAxis("Mouse X") > 0)
    5.           playerCamera.transform.Rotate(0, 0, -2.5F, Space.Self);
    Any help is greatly appreciated and thank you for your time :]
     
  2. UnityFuchs

    UnityFuchs

    Joined:
    Apr 18, 2018
    Posts:
    22
    Maybe this will help you to smooth your camera out.

     
    GrayWoolsey likes this.
  3. DangerDude_222

    DangerDude_222

    Joined:
    Mar 10, 2021
    Posts:
    2
    I was also looking to make an effect like this, I couldn't figure out how to make it swivel while moving the camera, but I did make an effect that slightly tilts the camera when pressing a and D!

    Here is the code, it's free for anyone to use:
     

    Attached Files:

  4. FeirntreeDev

    FeirntreeDev

    Joined:
    Jan 22, 2023
    Posts:
    4
    it doesn't let me look left or right when using this, how do I fix it?
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,713
    Please don't necro post. If you have a question, please start a new post.

    How to report your problem productively in the Unity3D forums:

    http://plbm.com/?p=220

    This is the bare minimum of information to report:

    - what you want
    - what you tried
    - what you expected to happen
    - what actually happened, log output, variable values, and especially any errors you see
    - links to documentation you used to cross-check your work (CRITICAL!!!)

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

    There's even a dedicated forum: https://forum.unity.com/forums/cinemachine.136/