Hi guys, I’m trying to simulate the effect of 2 colliders being stuck together so a ball will follow a terrain without jumping, I still want 3d movement but just don’t want it to catch air when it goes off a sloped area etc.
I’ve tried raycasting in front of the balls direction every frame and forcing the y value but that made the ball bounce into the air. Also tried very high friction values, but i still want the ball to roll around like its on ice.
Can anyone point me into a direction I may not of thought of?
Many thanks
You can apply a downward force to the ball on each frame when the ball is not in contact with something. MonoBehaviour defines callbacks called OnCollisionEnter and OnCollisionExit. These are activated when contact is made and broken, respectively. Basically, whenever there is no contact with the ground, send a raycast downward to detect the point directly underneath the ball and apply a downward force proportional to the distance from the ground like a spring. Note that you’ll have to take the radius of the sphere into account when measuring the distance. Also, contact is sometimes intermittent, so you might find it helps to wait for a few consecutive frames without contact before applying the force, depending on the dynamics of the game.