- Home /
How to follow exactly a curve ?
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.
Answer by Wolfram · May 22, 2012 at 02:47 PM
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).
Answer by eown70 · May 22, 2012 at 07:03 PM
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.
Your answer
Follow this Question
Related Questions
How to create magnetic platform in Unity 2D ? 0 Answers
Stick objects to player on contact 1 Answer
Move Object Along Ground Using Raycast 1 Answer
Stick player (my own rigidbody controller) to the ground when going down the slope 2 Answers
Player character 'jumps' or bounces off slope after leaving it instead of falling through the air 2 Answers