- Home /
Rigidbody car with wheel colliders gets stuck in ground
I have basically copied the car from the car tutorial and tried to change it, so it will follow a spline instead of being controlled by the player.
As long as I have the "AI" set throttle and steer, like a player would, the car behaves physically correct and stays on the road. But at higher speeds the AI has problems following the spline.
So instead I tried directly adding a force that will keep the car on the spline. Sadly this seems to mess up gravity / collision detection as the car either "floats" above the track, collides with it (leading to weird jumps / glitches) or falls through.
I have tried adding the force only in XZ direction, leaving the Y-axis to gravity, but that just leads to less floating and more ground collision.
Here is the relevant snippet of code: (targetPosition is a position further down the spline)
targetDirection = (targetPosition - transform.position).normalized;
targetVelocity = targetDirection * targetSpeed;
deltaVelocity = targetVelocity - rigidbody.velocity;
deltaAcceleration = deltaVelocity / Time.deltaTime;
rigidbody.AddForce(new Vector3(deltaAcceleration * rigidbody.mass, ForceMode.Force);
Any ideas?
Your answer
Follow this Question
Related Questions
Wheelcolliders launch the car. 0 Answers
how to set initial speed of vehicle 1 Answer
need tutorials for rigidbody.Addforce 1 Answer
Are y-axis wheelcolliders possible? 1 Answer
Perfect friction with WheelColliders 1 Answer