Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 laurG · Jun 28, 2017 at 12:50 AM · collisionphysicsrigidbodyvelocityjitter

Jittery Rigidbody

Hello!

I'm working on a 3D endless runner and I'm having a jitter related issue with my character's rigidbody. He is moving with the same velocity on the Z axis, but it has a lot of jitter:

Video showing the jitter - you can see the jitter better when jumping, but happens when just running as well most of the time.

Here is the setup I have in my project (settings that directly affect physics):

alt text

alt text

And here is how I control my character (script attached to the Player object, that contains the rigidbody):

 void FixedUpdate()
 {
  // I want the player to maintain this velocity, since he can run over ramps that would slow him down.
   m_rigidbody.velocity = new Vector3(_rigidbody.velocity.x, _rigidbody.velocity.y, speed);
 }

Other than this I have a simple Raycast in the LateUpdate() function to check for grounded status.

  if (Physics.Raycast(_rayToGround, out _groundRaycastHit, _distanceToCheckGround, distanceCheckMask))
 {
   // a few lines of simple code here to manage the state of the m_grounded boolean
 }

For jumping I use:

 public void Jump(float strength)
 {
      m_rigidbody.AddForce(_transform.up * strength, ForceMode.Impulse);
 }

The camera follows the Player smoothly, using a Lerp function and a reasonable speed, so it is not rigidly fixed on the target.

 void LateUpdate()
 {
        m_transform.position = Vector3.Lerp(m_transform.position, target.position + offsets, Time.deltaTime * speed);
 }

No other expensive code whatsoever in my project so far.

It's worth mentioning that in Editor there is almost no jitter (I'm thinking because of better performance, I run Unity on an octacore AMD processor 4 GHz, 32gb ram and Nvidia GTX 970 video card). The device I test on (also recorded the short video) is Huawei P9 Plus (64 GB). There shouldn't be any performance issues since I setup everything in an optimal way (no lights in the scene and only custom Unlit shaders optimized for mobile platforms, all textures compressed properly, the code I write always follows strict guidelines and industry standards, no memory leaks or other issues like that).

Does anyone know what could cause all this?

Thank you!

4.png (500.1 kB)
5.png (238.0 kB)
Comment
Add comment · Show 1
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 5c4r3cr0w · Jun 28, 2017 at 11:48 AM 0
Share

Have you tried changing interpolate options to interpolate or extrapolate? I think that would impact jitter enormously as it smooths the movement of the rigidbody.

"For the main characters or vehicles that are followed by the camera it is recommended to use interpolation."

ref

https://docs.unity3d.com/ScriptReference/RigidbodyInterpolation.html

4 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by laurG · Feb 28, 2019 at 10:03 PM

I changed to CharacterController in the end.

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
1

Answer by G3R1 · Jun 28, 2017 at 09:34 AM

If you are building this for a mobile game platform Android or iOS go to File>Build Settings>Player Settings> Other Settings and make sure multithreaded rendering is clicked(activated). This removed the jittering in my mobile game. Also if you want to increase your performance put these codes in the Awake function of your persistent gameObject if you have one:

 Application.targetFrameRate = 60; (you can set it to 30 frames if you want)
 Screen.SetResolution(720, 1280, true); (Resolution depends on your orientation and what your targeted device is...)

And don't forget to go in Edit>Project Settings>Quality and set "V Sync Count" to Every V Blank.

Comment
Add comment · Show 6 · 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 laurG · Jun 28, 2017 at 09:57 AM 0
Share

@G3R1 Thank you for your answer.

I can't tell if setting the $$anonymous$$ultithreaded rendering helped with this situation, but fixed an issue I was having someplace else, so thank you for this.

I had V Sync disabled before, setting it to Every V Blnk cases waaay more jitter than disabling it altogether.

For now I left multithreaded rendering on and disabled vertical sync, but I still have some jitter.

avatar image G3R1 laurG · Jun 28, 2017 at 10:14 AM 1
Share

I'm glad it helped you a bit...What is the games fps right now ? Did you optimize the number of polygons and what shaders are you using ? If you are on mobile you should always try to use mobile shaders that are not as heavy as standart shaders of unity or something else. Also enable interpolation on your rigidbody, maybe it helps. If you turn V Sync Count Off you are going to have other problems with your device like heating up etc. That is my experience. Also make sure you set the screen resolution by script because it increases the performance way too much, at least for my game it did.

avatar image laurG G3R1 · Jun 28, 2017 at 10:41 AM 0
Share

Please read my initial post, it says all that there. Also, you have screenshots of the profiler attached and the stats view in the game view attached.

Also you can see the FPS is 50/60 in the video.

Show more comments
Show more comments
avatar image
0

Answer by Ashokkumar-M · Jun 28, 2017 at 06:22 AM

Can you try setting Application.targetFrameRate = 60; in the start of the scene in the code. Then try running in the device.

@laurG

Comment
Add comment · Show 1 · 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 laurG · Jun 28, 2017 at 09:00 AM 0
Share

@Ashokkumar-$$anonymous$$ I am already setting the target frame rate to 60.

avatar image
0

Answer by AngelKraft · May 07, 2021 at 12:12 PM

After searching for hours on the Internet, your post saved me :) Just for other people to know if you have some laggy movement, this did the trick for me:

  1. Set the Rigidbody to Kinematic

  2. Rigidbody interpolation Project

  3. Settings > Quality > VSync Count: "Every Second V Blank"

The 3) is what made my GameObject move smoothly with rb.velocity = ...

Thanks again!

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.

Follow this Question

Answers Answers and Comments

139 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

Related Questions

Resume movement of instanced object relative to the original after instantiation. 2 Answers

Manually Apply Cars Collision Response Force 0 Answers

Why is there no Rigidbody2D.SweepTest() ? 1 Answer

Add velocity relative to ground? 1 Answer

Problem Trying to Apply Non-Kinematic Velocity to Rigidbody 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