- Home /
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.
1.4k views, and the question only got ONE vote so far... lol wtf?
yeah personally it says my account can't upvote it....not sure if only ad$$anonymous$$s can...but that wouldn't make sense...agreed though, this is a really useful thread if you're making an FPS game...
Answer by Eric5h5 · Mar 21, 2010 at 08:04 PM
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.
FixedUpdate is often the culprit when the FPS controller feels jerky, deselecting it solved a fairly annoying choppiness for me.
Answer by bruno martelli_legacy · Apr 17, 2010 at 09:05 PM
maybe its the computer thats running a bit slow?
Answer by Leocesar · Nov 27, 2011 at 04:54 AM
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!
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.
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.
Helpful follow-up comment regarding 12 as the frame counter, which was much smoother than 20 for me. 20 felt too "floaty" for my purposes. Thanks!
Answer by Anthony.du · Jul 12, 2010 at 07:58 PM
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.
Try deselecting "FixedUpdate" on the $$anonymous$$ain Camera.
Your answer
Follow this Question
Related Questions
The sprite that is being followed by thr camera is very jittery and doesn't look very nice at all. 2 Answers
How can I Make my orbit camera more smooth? 2 Answers
Rotate around object smoothly 1 Answer
Smooth camera rotation velocity. 0 Answers
How do I stop Smooth.LookAt, so I can move freely? 0 Answers