• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by SecurityOstrich · Aug 15, 2017 at 01:12 AM · movementmouselookfps controllerjitterjittering

Jittery FPS Camera when moving

I'm writing a basic FPS controller and using the following for mouse look:

 public float sensitivity = 1.0F;
         public float smoothing = 1.0F;
         private float minimumX = -80F;
         private float maximumX = 80F;
         float rotationX = 0F;
         float rotationY = 0F;
         float smoothedX = 0F;
         float smoothedY = 0F;
     
         void Update()
         {
             rotationX += Input.GetAxisRaw("Mouse Y") * sensitivity;
             rotationY += Input.GetAxisRaw("Mouse X") * sensitivity;
     
             rotationX = Mathf.Clamp(rotationX, minimumX, maximumX);
     
             smoothedX = Mathf.Lerp(smoothedX, rotationX, 1.0F / smoothing);
             smoothedY = Mathf.Lerp(smoothedY, rotationY, 1.0F / smoothing);
     
             transform.localEulerAngles = new Vector3(-smoothedX, smoothedY, 0.0f);
         }

I have been stuck for days trying to get my player to rotate in the camera direction so that they can walk forward based on where you look. I have tried many things and all of them result in either the player not turning, or it "working" but having the camera get choppy whenever I move AND rotate at the same time.

I am moving the player like this:

     private void GetInput()
     {
         vInput = Input.GetAxis("Vertical");
         hInput = Input.GetAxis("Horizontal");
         jumpInput = Input.GetAxisRaw("Jump");
     }    
 
     private void Run()
     {
         vel.z = vInput * speed;
         vel.x = hInput * speed;
     }
 
     private void Update()
     {
         GetInput();
         Run();
         Jump();
         rb.velocity = transform.TransformDirection(vel);
     }

Can someone please explain to me how to properly do this setup and how to stop the camera jitter? Both the camera and the player are being rotated in Update() so I don't think they should be out of sync in their movements but I must be misunderstanding something.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Destolos · Aug 15, 2017 at 09:27 AM 0
Share

I tested your scripts and it worked for me. Good examples for FPS-controller are in the StandardAssets.

avatar image x4637x · Aug 15, 2017 at 11:00 AM 0
Share

Try move rb.velocity = transform.TransformDirection(vel); to FixedUpdate().

avatar image ryisnelly · Sep 07, 2017 at 10:55 AM 0
Share

have you tried disabling V sync?

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by kingkdaboss567 · Sep 07, 2017 at 10:51 AM

Try Fixed Update

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Babul2 · Sep 07, 2017 at 12:00 PM

Use "Time.deltaTime"

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by EagleDeveloper · Aug 07, 2020 at 08:10 PM

Hey @SecurityOstrich ,

Sorry for the late Reply

Actually, I had the same problem, It actually is very simple.

Just change this:

          rotationX += Input.GetAxisRaw("Mouse Y") * sensitivity * Time.fixedDeltaTime;
          rotationY += Input.GetAxisRaw("Mouse X") * sensitivity * Time.fixedDeltaTime;
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

103 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

First Person Player 3 Answers

Jittery camera motion in GearVR when moving camera - nothing seems to work. 2 Answers

Movement jitter every few seconds 1 Answer

Proper Fixed Timestep for 30 FPS 1 Answer

Anyone have a sensitivity slider script/tutorial used for an fps (using Unity's mouselook controller?) 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges