I am making a 3D basic runner game, where my character constantly "runs" in a constant pace. At first I used MovePosition() to implement the movement behavior, but I encountered a weird behavior while colliding with other rigidbodys, especially dynamic rigidbodys. So I tried using AddForce() instead -
Vector3 desiredVelocity = new Vector3((transform.forward.normalized.x * playerSpeed), 0f, 0f);
rb.AddForce(desiredVelocity - rb.velocity, ForceMode.VelocityChange);
The collisions behave fine now, but I'm having issues with the gravity - With this implementation, the rigidbody gets "pushed" forward and the bigger the force added to it, the lower gravity gets, and it becomes kind of a trade-off, where increasing gravity makes the player "slower" and increasing the force added makes the gravity effect lower. Pretty intuitive physics issue.
I'm not sure if there's a simple solution for this physics issue or should I approach it differently. What would be the proper, standard implementation for this kind of movement?
Thank you in advance, Omer