x


First Person Camera is extremely jerky

In the official island demo the First person Camera has extremely jerky movement which I've never been able to figure out. I've trawled the forums for days not believing that I'm the only one to notice this or have the issue. All the demos utilising the FPS script exhibit this problem.

The closest answer I've found is to put all all camera movement into FixedUpdate. Which I think I did, but no change. I edited all the scripts Mouselook, FPSWalker etc to use FixedUpdate. Is that the right thing to do? It made no difference to the poor camera movement. Could someone explain how to implement a solution to get a smooth FPS camera result in a demo.

Coming from Blitz3D I'd implement a smoothing queue or damping etc. I just refuse to believe this technology is demoed with such a rubbish camera script and movement, please let me into the secret.

more ▼

asked Mar 21 '10 at 07:38 PM

user-1770 (google) gravatar image

user-1770 (google)
26 1 1 2

1.4k views, and the question only got ONE vote so far... lol wtf?

Dec 14 '11 at 06:22 AM Lo0NuhtiK

yeah personally it says my account can't upvote it....not sure if only admins can...but that wouldn't make sense...agreed though, this is a really useful thread if you're making an FPS game...

Dec 14 '11 at 04:56 PM flannerus
(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

Must be something in your system, because there's nothing jerky about it here or on any other computer I've used. Putting a first-person camera script in FixedUpdate is not the right thing to do...that will make it only update when the physics system updates, instead of every frame. Try turning off any mouse hacks or utilities you might be using.

more ▼

answered Mar 21 '10 at 08:04 PM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

FixedUpdate is often the culprit when the FPS controller feels jerky, deselecting it solved a fairly annoying choppiness for me.

Dec 13 '11 at 08:42 PM flannerus
(comments are locked)
10|3000 characters needed characters left

maybe its the computer thats running a bit slow?

more ▼

answered Apr 17 '10 at 09:05 PM

bruno martelli gravatar image

bruno martelli
135 10 13 24

(comments are locked)
10|3000 characters needed characters left

Searching the forums I found the following script and it solved my FPS camera movement (I’ve made some adaptations to the original script to fit my needs. Sorry, I don't know who the author is).

    using UnityEngine;

using System.Collections;

using System.Collections.Generic;



public class SmoothMouseLook : MonoBehaviour

{

    /*

    This script is used to average the mouse input over x 

    amount of frames in order to create a smooth mouselook.

    */



    //Mouse look sensitivity

    public float sensitivityX = 2f;

    public float sensitivityY = 2f;



    //Default mouse sensitivity

    public float defaultSensX = 2f;

    public float defaultSensY = 2f;



    //Minimum angle you can look up

    public float minimumY = -60f;

    public float maximumY = 60f;



    //Number of frames to be averaged, used for smoothing mouselook

    public int frameCounterX = 35;

    public int frameCounterY = 35;



    //Mouse rotation input

    private float rotationX = 0f;

    private float rotationY = 0f;



    //Used to calculate the rotation of this object

    private Quaternion xQuaternion;

    private Quaternion yQuaternion;

    private Quaternion originalRotation;



    //Array of rotations to be averaged

    private List<float> rotArrayX = new List<float> ();

    private List<float> rotArrayY = new List<float> ();



    void Start ()

    {

       //Lock/Hide cursor

       Screen.lockCursor = true;



       if (rigidbody)

         rigidbody.freezeRotation = true;



       originalRotation = transform.localRotation;

    }



    void Update ()

    {

       if (Screen.lockCursor) {

         //Mouse/Camera Movement Smoothing:   

         //Average rotationX for smooth mouselook

         float rotAverageX = 0f;

         rotationX += Input.GetAxis ("Mouse X") * sensitivityX;



         //Add the current rotation to the array, at the last position

         rotArrayX.Add (rotationX);



         //Reached max number of steps?  Remove the oldest rotation from the array

         if (rotArrayX.Count >= frameCounterX) {

          rotArrayX.RemoveAt (0);

         }



         //Add all of these rotations together

         for (int i_counterX = 0; i_counterX < rotArrayX.Count; i_counterX++) {

          //Loop through the array

          rotAverageX += rotArrayX[i_counterX];

         }



         //Now divide by the number of rotations by the number of elements to get the average

         rotAverageX /= rotArrayX.Count;



         //Average rotationY, same process as above

         float rotAverageY = 0;

         rotationY += Input.GetAxis ("Mouse Y") * sensitivityY;

         rotationY = ClampAngle (rotationY, minimumY, maximumY);

         rotArrayY.Add (rotationY);



         if (rotArrayY.Count >= frameCounterY) {

          rotArrayY.RemoveAt (0);

         }



         for (int i_counterY = 0; i_counterY < rotArrayY.Count; i_counterY++) {

          rotAverageY += rotArrayY[i_counterY];

         }



         rotAverageY /= rotArrayY.Count;



         //Apply and rotate this object

         xQuaternion = Quaternion.AngleAxis (rotAverageX, Vector3.up);

         yQuaternion = Quaternion.AngleAxis (rotAverageY, Vector3.left);

         transform.localRotation = originalRotation * xQuaternion * yQuaternion;

       }

    }



    private float ClampAngle (float angle, float min, float max)

    {

       if (angle < -360f)

         angle += 360f;

       if (angle > 360f)

         angle -= 360f;



       return Mathf.Clamp (angle, min, max);

    }
    }

Steps to use it: Add a First Person Controller to the scene and remove the Mouse Look script all together 1) Attach Smooth Mouse Look to the Character Controller with this parameters:

Sensitivity X: 4 Sensitivity Y: 0 Default Sens X: 4 Default Sens Y: 0 Minimum Y: 0 Maximum Y: 0 Frame Counter X: 20 Frame Counter Y: 20

2) Attach another Smooth Mouse Look to the Main Camera with this parameters:

Sensitivity X: 0 Sensitivity Y: 5 Default Sens X: 0 Default Sens Y: 5 Minimum Y: -60 Maximum Y: 60 Frame Counter X: 20 Frame Counter Y: 20

That’s it!

more ▼

answered Nov 27 '11 at 04:54 AM

Leocesar gravatar image

Leocesar
98 1 2 4

Reeeeaaally awesome script here, I've found that lowering the Frame Counter to about 12 makes for a much less "floaty" feel. Wish I could upvote (dunno why it wont let me) because this script will be integral to my game.

Dec 13 '11 at 08:45 PM flannerus

The value used in FrameCounter depends on the effect you are trying to achieve. For a underwater or slow motion situation 20 to 25 will convey the right feel. And 12 is a good number for a normal FPS. I felt it also and updated my game to use "12" and it's really better this way. Thanks to test it out flannerus.

Dec 14 '11 at 06:14 AM Leocesar
(comments are locked)
10|3000 characters needed characters left

I have the exact same problem as the person wrote above. I once had Unity on an old machine and it was a bit jumpy then. I now have a Core i3 computer with Intel HD graphics and it is very jerky. I have gone through all the graphics settings but it hasn't changed anything.

more ▼

answered Jul 12 '10 at 07:58 PM

Anthony gravatar image

Anthony
1

Try deselecting "FixedUpdate" on the Main Camera.

Dec 13 '11 at 08:43 PM flannerus
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3014
x207

asked: Mar 21 '10 at 07:38 PM

Seen: 3955 times

Last Updated: Dec 14 '11 at 04:56 PM