Adding force makes object rotate.

I’m making a simple infinite block dodging game, but in 3D. To do so, I’ve created spawners that send blocks down a dragless ground, which are then destroyed at the end, and the player can move left and right using the right and left keys.

This is how I’m capturing this, using FixedUpdate():

if (Input.GetKey("left"))
        {
            corpo.AddForce(-20 * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
        }
        if (Input.GetKey("right"))
        {
            corpo.AddForce(20 * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
        }

As simple as this go, whenever I’m adding force in any side of this axis, the object slowly rotates to the left. When checking by the inpector, the Y (in transform.rotation) starts to add up some negative numbers, and the block I’m using will be seen turning to the left slightly.

I don’t want to fix the rotation, as it would be a buzzkill when the player controlled object collides with the obstacles that are pouring down.

Is there any ways to fix this? This is the only script that are affecting the player Object except for the collision one and another one that restarts the game a second after the collision happens. Cube is default, same with obstacles.

I am assuming this is a bug.

Thank you for your time, appreciate any help
S.B

Just to clarify: The dragless ground is a stretched cube (scale proportions: X 10, Y 1, Z 100) with PhysicMaterial attached to it, where dynamic friction is 0, static friction is 0, bounciness is 0, average x2.

The block’s box collider is probably picking up some eccentric loading from the ground object. Here are some options:

Make sure you have the zero friction material applied to both the block box collider AND the ground collider.

I would avoid relying on a box collider moving smoothly over anything, there is too much potential for the corners to go wrong due to floating point precision. Have you considered adding a capsule collider at the centre that provides a tiny ground clearance (and freeze the x and z rotations)?

With more complexity, you could use freeze constraints that you release on collision with a player object.

Thanks for all the tips and options, appreciate the help!

I ended up using the freeze axis and release on collision method, but I’m still curious about what could be making this glitch. Likewise, I also thought about something funky with floating point precision.

Is there another way to report this as a bug to any of the developers so they could check it out? I mean… My project is quite small, and mostly a hobby, but there must be someone relying on AddForce for simulations and stuff…?

Edited: I’ve tested using the same zero friction material on the player’s block as well, and it did work on avoiding the slow rotation to the left but it also removed a little bit of the feedback from the side push (no drag), being slightly detrimental to the “feel” of the movement. Just felt like adding this here, to anyone who might be experiencing similar problems.

If you have friction forces, you can imagine that any variation out of the horizontal position of either the cube or the surface it rests upon will introduce a torque on the cube. At the same time there are many floating point calculations taking place in the physics engine that could result in very small precision changes in those values. This isn’t really a bug, just a function of a general purpose physics engine, optimised for performance in a game environment, using single precision numbers.

The chances are this is actually in Nvidia’s PhysX which is used to work out the 3D physics, rather than anything the Unity developers have coded.

You should note that friction behaviour is controlled by the physics materials on both of the colliders. So you can set zero friction on the cube and floor for sliding, but then a high friction material on your player (with use maximum), to get better interaction with them.