The symbol vibrates when moving 30 frames per second

I am developing a 2.5D mobile game with Unity. To move the character back and forth, I use a piece of code inside the update function:

void Update () { if (shouldMove==true){ transform.Translate(Vector3.forward * 3 * Time.deltaTime); } } 

Thus, the code works very well when the game runs at 60 frames per second, but when the fps drop to 30 or less, the character starts to vibrate while moving. I tried to test the same code on flat terrain, and it worked well, so maybe the problem is a collision between the character and the landscape colliders. However, I do not understand why, if the fps are high, it works well. I tried both the capsule collider and the grid wallet, but no one worked. What do you think? Should I try to use different code?

Edit 1: I use a capsule collider and a tough figure. Should I use a character controller?

+4
source share
2 answers

Sam Bowens is absolutely right in his answer, however this problem usually arises due to an excess of objects (especially those that are animated). This can severely degrade performance.

You should try to remove some objects and try if your character is still vibrating. If this is not so, then I'm right. Of course, you don’t want to delete objects of your scene, so you can add an asset such as SmartLOD , which removes the geometry of these objects from objects that are not displayed on the screen and thus improve the performance of your game.

Hope this helps.

+3
source

I had a similar problem with a ball that vibrates on the ground. This was caused by gravity, which pulls the game object to the ground, then it collides on the ground and bounces. If your problem is the same as mine, you need to either set up Fixed Timestep (Edit => Project settings => time), and / or Bounce Threshold (Edit => Project settings => Physics).

By increasing the failure threshold, you will increase the minimum speed below which the object will not bounce, so that gravity is not large enough so that the speed of the ball exceeds the failure threshold.

By decreasing the physical time step, you reduce the effect of gravity on each time step because the time steps are less, and therefore the amount of speed added to the game object for each time time is less.

EDIT: You can also see the speed of sleep (Edit => Project Settings => Physics), because if it is higher than the speed of gravity, the object should not vibrate.

+3
source

Source: https://habr.com/ru/post/1490682/


All Articles