Rigidbody Unwanted Drift
I'm making a simple 3D endless runner game. For now let's say it's a character moving forward in a plane with two boxes as side walls. Then I noticed a "bug". If my character (A car shaped rigid body) collides with the side walls (simple box colliders), sometimes it drifts away on the X axis. Can be both to the left or to the right and in different speeds. It's hard to debug when it only happens sometimes.
I've also written my movement vector on the console to see if it was getting unwanted value but it's just a Vector3(0,0,0).
The character:
Is frozen on all axis rotation.
Don't use gravity.
Have a discrete collision detection.
Here's my code:
void FixedUpdate() {
rBody.angularVelocity = Vector3.zero;
moveVector = Vector3.zero;
// x
// Unnecessary, I'm using GetRawAxis ("Horizontal");
if (Mathf.Abs (x) > keyInputDelay)
moveVector.x = x * hSpeed;
// y
moveVector.y = transform.position.y * -1;
// z
moveVector.z = 1 * vSpeed;
moveVector *= Time.deltaTime;
rBody.MovePosition (transform.position + moveVector);
Answer by andsegcar · Oct 25, 2017 at 02:37 PM
Ok... So I "Fixed" it by increasing the draft. which means the object will stop it's weird movement before it is noticeable. Not the best fix but for my game it's enough.
Your answer
![](https://koobas.hobune.stream/wayback/20220612141820im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Collision between objects not being detected 0 Answers
Throwing an object whilst moving 1 Answer
Problem with rigidbody 2 Answers
Rigibody constraints do not work. Still moves a little. 4 Answers
My player spins when I enter play mode. What am I missing? 0 Answers