(I’ve tried all the solutions I could find on this forum with no result. See “What I Tried” for more details.)
The Issue:
The car in my game is moving through walls on my racetrack. The best result still had the car bounce off the wall a few times, but suddenly clip into the wall at about 10 x Time.deltaTime (a slow speed). After troubleshooting I found that this is clearly an issue with using mesh colliders for the walls, but it would be literally impossible for me to convert my racetrack’s walls to box colliders. How do I make curved walls for my racing game that the car will actually collide with?
The Setup:
The car is a convex mesh collider with a rigidbody with Y position constraint frozen and XYZ rotation constraint frozen (This needs to be done for the type of movement I’m doing and works fine when I use boxes as the walls; setting all constraints off doesn’t fix the issue). The walls of the road are a mesh collider and follow a smooth curve. All the faces are facing the right way.
Using a straight plane as the road with box colliders as the walls, the collisions work perfectly (even when i change the box colliders to mesh colliders), so
the problem is using mesh colliders for walls with multiple faces as the car is clipping between the vertices.
The walls are made using boxes following a bezier curve in Blender. The car moves using transform.Translate on a FixedUpdate.
What I tried ([X] denotes steps that worked for the plane with two boxes setup) :
- Continuous collision checking
-
Project Settings > Physics > Default
Max Depenetration Velocity = 1000 - DontGoThroughThings.cs
- Continuous Dynamic/Continuous Speculative collision detection
- Setting the player collider to a box/capsule collider
- Switching car movement to rb.AddForce()
How I made the walls:
- New Scene in blender
- Make a bezier curve
- Make a cube > Edit mode > Move it X units to the right
- Add an array modifier and a curve modifier, set the length to fit
curve, merge set to true on the array
mod - Apply the array mod, apply the curve mod
- Export as FBX, import to unity
Surely some Unity game out there uses curved walls this happening, so I’m open to learning about any pipelines for making racetracks with curved walls.