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
1
Question by Sameer1472 · Oct 06, 2020 at 10:13 AM · rigidbodycamera-movementplayer movementfps controller

Laggy FPS Camera (attached to rigid body player), I have tried everything. Unity wizards need to be summoned for this one.

EDIT: I FOUND THE SOLUTION FINALLY: The problem was with the camera rotation controlling part of the script. I was rotating the Camera as well as the Rigidbody to which the camera was attached in the mouse script. So the way to fix this was, only rotate the camera on the Y axis but not the rigid body, after that you can figure out how you want to handle the rigidbody rotations. If this doesn't make sense then please keep reading: Dani (a popular game dev youtuber) is working on a game called karslon, and he has a tutorial where he also publicly released the karslon's movement code: https://www.youtube.com/watch?v=XAC8U9-dTZU&t=126s I just downloaded the script files and compared what he did differently. For me I explained what I did wrong above, but go ahead and take a look at dani's files and see if they help.

Situation: I have an FPS character, which is a rigidbody, and the camera is attached to it.

Problem: The camera has lag/jitter, which is especially noticeable when player is moving and rotating

VIDEO OF THE PROBLEM: https://youtu.be/DQk31iOa0-Q

concentrate on the house to see how bad the lag is.


What I already understand: I know the lag is due to the rigid body character's movement being handled in the FixedUpdate function, I'm using addforce to add the character movement

What I've Tried: I tried putting the camera movement and rotation in the Update and LateUpdate. There is no noticeable difference. I've also set the rigidbody's interpolation to interpolate. It makes no difference at all and I thought for sure setting the interpolation to interpolate would make some noticeable difference atleast. It almost feels like the interpolation is not being applied. Is that possible?


Code:

Camera Controller

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerCameraController : MonoBehaviour
 {
     [SerializeField] private float lookSensitivity;
     // Start is called before the first frame update
 
      private GameObject player;
     float xRotation =0.0f, yRotation = 0.0f;
 
 
 
     private void Start()
     {
         player = transform.parent.gameObject;
     }
     // Update is called once per frame
     void LateUpdate()
     {
         RotateCamera();
         setCameraPos();
     }
 
     private void RotateCamera()
     {
         float mouseX = Input.GetAxisRaw("Mouse X") * lookSensitivity * Time.deltaTime;
         float mouseY = Input.GetAxisRaw("Mouse Y") * lookSensitivity * Time.deltaTime;
         xRotation -= mouseY;
         yRotation += mouseX;
         transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
         player.transform.localRotation = Quaternion.Euler(0f, yRotation, 0f);
         
     }
     private void setCameraPos()
     {
         transform.position = player.transform.position;
     }
 }
 




PlayerMovementController:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerMovementController : MonoBehaviour
 {
     [SerializeField] private float moveForce = 0.0f;
     [SerializeField] private float jumpForce = 5.0f;
     [SerializeField] private float groundCheckRay = 0.0f;
     private Rigidbody playerBody;
     private void Start()
     {
         playerBody = GetComponent<Rigidbody>();
     }
 
     private void Update()
     {
         Jump();
     }
 
     private void FixedUpdate()
     {
         Move();
     }
     private void Move()
     {
         float hAxis = Input.GetAxisRaw("Horizontal");
         float vAxis = Input.GetAxisRaw("Vertical");
 
         Vector3 horizontalMovement = transform.right * hAxis;
         Vector3 verticalMovement = transform.forward * vAxis;
 
         Vector3 local_movement_direction = (horizontalMovement + verticalMovement).normalized;
 
         playerBody.AddForce(local_movement_direction * moveForce * Time.fixedDeltaTime);
     
     }
 
     private void Jump()
     {
         if (isGrounded())
         {
             if (Input.GetKeyDown(KeyCode.Space))
             {
                 playerBody.AddForce(0, jumpForce, 0, ForceMode.Impulse);
             }
         }
     }
 
     private bool isGrounded()
     {
         Debug.DrawRay(transform.position, Vector3.down * groundCheckRay, Color.blue);
         return Physics.Raycast(transform.position, Vector3.down, groundCheckRay);
     }
 }
 



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

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

How do I stop my player or camera from jittering during player movement? 1 Answer

Rigidbody movement in direction of camera? 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

Camera script for ball not working as intended, looking for some tips, or advise. 0 Answers

Issue with Instantiate and the instant that spawns on a moving object that rotates 1 Answer


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