I’m having some trouble getting a smooth movement of an object sliding “on rails”.
Forgive me for being so vague or overly general here - but I can’t really be any more specific as the project is not yet public, but think of something like a train for now.
I have set up a mesh collider for the surface where the object is supposed to slide on and the object itself has a box collider.
The idea “works”, but it’s a rather horribly jagged movement and what I’m after a nice smooth slide.
I have very little experience in tuning the physics for something like this, but I’ve tried different types of colliders and physic materials, so far with very little difference.
I have also tried to change the slide surface geometry but I’m not sure if I should be adding (way) more polygons or quite the opposite?
There is some code in this thread that shows how to use a Bezier curve to plot a smooth path between points. There is also a script in this thread that shows how to use physics to move an object smoothly over a rough surface (it is actually used with a camera, but the same principle works with any object).
Ask again if neither of these techniques is what you are looking for.
Do you mean, that I should not use actual collision detection to make the object “stay on rails”, but rather use something like that script, or perhaps combine them?
Because it’s the collision detection part that is giving the jagged movement in my original project.
It’s a great script by the way, I played with it a bit and made one cube “chase” others in a scene - kind of like a magnet pushing another with same polarity
Physics simulations in games today are not yet accurate or efficient enough to use them for making something stay on rails. Using a kind of spline based solution, like the one Andy linked to, is the way to go.
I’ve just thought of something else that might help you out, but I’m not too sure…
Is it possible to use, say, four SphereColliders instead of a BoxCollider for your object (putting them at the corners)? You might get a smoother result if you do this and also enable SmoothSphereCollisions on the MeshCollider.