I'm trying to achieve smooth movement for a ball. I seem to be failing to achieve this and now I've created a sample scene, which shows my setup from the game and the problem exists in that sample scene, as well.
I've uploaded the sample project to github: https://github.com/iQew/PhysicsTesting (open Assets/Scenes/SampleScene)
Here's a recording of the problem. It's a bit more extreme here than it is in the editor, but it shows the problem even better because of it: https://i.stack.imgur.com/xY30j.jpg
Scenario: I have a 2D mobile game (android) using Unity 2019.4.14f1 with URP. The camera does not move and will always have the same settings. The playfield consists of a certain area, which is blocked in by walls, which have a BoxCollider2D on them. The ball is a simple sprite with a CircleCollider2D, RigidBody2D and a Trail Renderer.
I have deleted all quality settings except the "Low" one, which has VSync Count set to "Don't Sync". In the Awake block of a controller script I set the Application.targetFrameRate to 60. In the Start block I use BallRigidBody2D.AddForce(new Vector2(1f, 10f), ForceMode2D.Impulse) to make the ball move.
The RigidBody2D of the Ball has the following settings:
- Body Type: Dynamic
- Material: DefaultBall (a Physics2D material with friction: 0 | bounciness: 1)
- Simulated: true
- Use Auto Mass: false
- Mass: 0.025f
- Linear Drag: 0
- Angular Drag: 0
- Gravity Scale: 0
- Collision Detection: Continous
- Sleeping Mode: Start Awake
- Interpolate: Interpolate
All other project settings are at default.
When I launch the game, the ball starts moving as expected. Most of the time the movement is smooth, but there is stuttering every now and then. I am wondering, if there is a way to make this stuttering go away. The tutorials I found on the internet, which solve this exact problem set the Interpolation mode of the RigidBody2D to "Interpolate", but I did that and there's no change.
There are no other scripts interfering with the physics calculation at all. So, I assume this has to do with some kind of project settings? Using a smaller Fixed Timestep does not help, in fact it gets a lot worse, if I use 1/120 for example.
Any help would be greatly appreciated!