Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 supa4plex2 · Jul 01, 2020 at 02:27 PM · inputcharactercontrollerplayer movementcamera rotatelatency

Problems with Player Movement and Camera Movement clashing, any solutions?

Hi,

I've already done work on Unity2D and have decided to pop into Unity3D in order to experiment with some things. I set up some simple things around the scene (playing area and a player) to play around with things. I followed Brackeys' tutorial on a simple player movement & first person camera controller, as shown here: https://www.youtube.com/watch?v=_QajrabyTJc

After a bit of tweaking, both the player and the camera move fine individually. The problem arises when they're both used at the same time; if I were to move any direction whilst moving the mouse, some 'jankiness' occurs.
Basically, the mouse begins to move in a jittery/choppy motion, and both mouse & movement inputs become quite delayed. This means that if I were to let go of my inputs it would take a while before the movements from the player or the camera actually stop. If I were to be going forward and then suddenly switch my input to go right (or look right) it would take a while for my player to actually turn right.

I hope my explanation makes sense. If not, ask me to clarify.


Here's my scripts (although I honestly doubt it's a problem in the scripts, please do prove me wrong if there is):

Player Movement

 using UnityEngine;
 
 public class PlayerMovement : MonoBehaviour
 {
     // Components
     [SerializeField] private CharacterController charControl = null;
 
     // Player Properties
     [SerializeField] private float walkSpeed = 8f;
 
     void Start() => charControl = GetComponent<CharacterController>();
 
     void Update()
     {
         float moveX = Input.GetAxisRaw("Horizontal");
         float moveZ = Input.GetAxisRaw("Vertical");
         Vector3 moveDir = ((transform.right * moveX) + (transform.forward * moveZ)).normalized;
 
         if (moveDir.magnitude >= 0.01f)
         {
             charControl.Move(moveDir * walkSpeed);
         }
     }
 }


Camera Controller

 using UnityEngine;
 
 public class MouseMovement : MonoBehaviour
 {
     // Components
     [SerializeField] private Transform playerTransform = null;
 
     // Camera Properties
     [SerializeField] private float mouseSensitivity = 10f;
     private float xRot = 0f;
 
 
     void Start() => Cursor.lockState = CursorLockMode.Locked;
 
     void Update()
     {
         float mouseX = Input.GetAxisRaw("Mouse X");
         float mouseY = Input.GetAxisRaw("Mouse Y");
 
         // Determines the angle to rotate the Camera on the X axis (up and down)
         xRot -= mouseY * mouseSensitivity;
         xRot = Mathf.Clamp(xRot, -90f, 90f);
 
         // Calculates how much the Player Transform needs to rotate
         Vector3 yRot = Vector3.up * mouseX * mouseSensitivity;
 
         transform.localRotation = Quaternion.Euler(xRot, 0f, 0f);
         playerTransform.Rotate(yRot);
     }
 }



I've tweaked them, so they're a tiny bit different from the video but they're practically similar. I'll add this just in case: I've tried these out both with and without the tweaks, and they both showed the same problem, so the tweaks didn't affect anything.

I never had this issue with latency in Unity2D, so I honestly don't know what's going on. If I were to guess, I'd say it has to do with my framerate, but I slightly doubt that as well. My laptop is quite old, just for reference.


Ways I've tried to deal with it so far:


  • Printing the values of the necessary variables to the console (no surprise, the values behaved relative to what was going on on-screen).

  • Playing around with the mouse sensitivity. For some reason a higher sensitivity just slightly improves it, but we're talking about extremely high sensitivity values for very minor improvements.

  • Playing on Maximised mode (no difference).

  • Swapping the CharacterController for a Rigidbody-based player controller. I think I should test this once again, but a similar problem still persisted from it.

  • Changing the Input.GetAxis()parts (from Brackeys' video) to Input.GetAxisRaw().



Thanks for taking the time to read!

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

175 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 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

Problem in rotating camera around a moving player 1 Answer

Input System Can't Catch Event on Update 0 Answers

Why am I losing some inputs on Update function? 0 Answers

How do I have multiple controls for the same function? (Controller and Keyboard) 1 Answer

I'm a bit new but when my camera rotates with the player model to look around it kind of jitters 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges