Lay a Sphere on a Point

I am making a fantasy soccer game with custom ball physics and I have this problem.



I dont know how to achieve the desired result. Maybe something related to equations?

Move the sphere in the direction of the spherecast by an amount equal to the RaycastHit.distance

@DavidRochin I suggest you take a look the Physics.SphereCast
it’s exactly what you want to achieve on picture (3), even the edge & distance
or
here is my raycast plugin to help you visualize how the raycast work.
Raycast Gizmos Visualizer
https://youtu.be/MFLAn25ca9A

SphereCast’s distance are calculated to ignore the radius, so just use that RaycastHit.distance as result.

  • assume that “Ball” model have perfect center point.
  • assume the model radius are equal to SphereCast radius.

Try this:

 ball.position = hit.point + (ball.position - hit.point) * ball_radius;