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
  3. Dismiss Notice

Question Camera stutters a lot when looking around (need help)

Discussion in 'Editor & General Support' started by kavgiorgos12, Jul 26, 2020.

  1. kavgiorgos12

    kavgiorgos12

    Joined:
    May 3, 2020
    Posts:
    15
    Hello,

    I've looked everywhere about this and tried a lot of things but havent found a solution. Basically I have a first person controller in my game and when I enter game mode the camera stutters like crazy. Any answers to my questions will be greatly appreciated. The controller I'm using is one I donwloaded here it is:
     
  2. hotcarl

    hotcarl

    Joined:
    Aug 21, 2017
    Posts:
    18
    Can you post the code you're using?

    Some things to check/try:

    1. Use LateUpdate() to move your camera. Sometimes using Update() loop can be an issue.
    2. Make sure you put the LookAt() code AFTER the code where you move the camera. This is more pronounced in higher speed objects.
    3. Use Quaternion.Slerp (or Quaternion.Lerp) to smooth the camera movement. Mmake sure the movement speed isn't too high. Example:

    Code (CSharp):
    1. private Transform lookAt;
    2. private float smoothSpeed;
    3.  
    4. void Start()
    5. {
    6.         lookAt = GameObject.Find("Player");
    7. if (smoothSpeed < .1f)
    8.         smoothSpeed = 2;
    9. }
    10.  
    11. void LateUpdate()
    12. {
    13.         // Remember to move first //
    14.         camera.transform.position += new Vector3(10,10,10); // This can be whatever your camera movement logic is.
    15.  
    16.         // Then LookAt last. Always do LookAt last. //
    17.         // Otherwise you're turning the camera at location A, then moving the camera location B. Subsequently, the camera probably is pointed at the wrong thing //
    18.         lookAt.LookAt(player.position);  
    19.         transform.rotation = Quaternion.Slerp(transform.rotation, lookAt.rotation, (Time.deltaTime * smoothSpeed));        
    20. }
    Note: If you're not using the Time.deltaTime modifier, then that will essentially nullify the benefits of Slerp/Lerp
     
  3. kavgiorgos12

    kavgiorgos12

    Joined:
    May 3, 2020
    Posts:
    15
    Hi thanks for the reply. I uploaded the images from the script I'm using. Also my controller has several parts I also uploaded an image about that. Also I am not that familiar with Unity, I only started a month ago so I don't understand what you're saying. Thanks for your time!
     

    Attached Files:

  4. hotcarl

    hotcarl

    Joined:
    Aug 21, 2017
    Posts:
    18
    Hi. Only been doing this a month, eh? Welcome to the asylum. I started banging my head against the Unity wall a couple years ago. Hardly notice the concussion anymore. Published my first game a month ago. Have since learned a bunch of better ways I could have wrote since then.

    From the screen shots you provided, it would seem as if you're using an existing project that you didn't write yourself. There isn't anything wrong with that. It's a great way to learn. While you did post what I requested, there is unfortunately more I would need to see to begin diagnosing the issue.

    Since you didn't understand what I suggested in my first post. Forgive me for being presumptive, but I am guessing you're still getting your footing with the programming aspects of Unity. I would recommend doing some of the free tutorials Unity has online. They're surprisingly good. I think jumping into the middle of an established project like you are would be overwhelming to me, and like I said, I've been doing this for a couple years, and even published a (simple) game.

    Good luck :)