I have a ball collider that rolls along a descent with some little hills. But with the speed, the ball is jumping and I wish that it follows exactly the curve of the slope. How can I achieve this, using physics? I tried to apply a constant force down and increase the gravity, but it isn’t perfect. Is there a property to really stick curve, like a magnet … ? (maybe static friction, but it doesn’t work…)
Thank a lot.
You could add a script that forces localPosition.y to a certain value. You’d need a Raycast from the center of your ball straight down, or if the floor is a Unity Terrain, you can use Terrain.SampleHeight().
Adding the ball radius to the resulting coordinates will give you your new ball center.
If the motion of the ball is determined by Unity’s physics, you’d have to experiment whether this combines well with Unity’s physics calculations (i.e., it might be enough to put your distance offsetting in FixedUpdate(), but it might produce jittering artifacts if it conflicts with the physics engine).
Thanks a lot :), I haven’'t used the localPosition.y because I had some little bugs with it, like strange friction. But with the raycast, I obtained the normal and applied an inverse force to my ball. It works very well. Thanks.