I refactored your fiddle a bit for a simple (possible) solution: https://jsfiddle.net/683wL4qe/
The idea is to compute the distance from the mesh position to the plane and then subtract this value from the y-component of ball.position
. But before doing this, you multiply the distance with a value lower than 1 (e.g. 0.2
) in order to have a smooth transition.
Note: At the beginning, the ball moves from (0, 0, 0)
onto the plane. This can be avoided if you directly assign a valid start position when the mesh is added to the scene.
I’m not sure I understand your raycasting code in intersectTerrain()
so I just compute the distance to the plane via Plane.distanceToPoint()
which should be a good approximation. It’s also faster than a raycast. The approach is not a perfect solution but it might be sufficient for certain use cases.