- Home /
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?
Answer by Buckslice · Jan 17, 2018 at 12:46 AM
Move the sphere in the direction of the spherecast by an amount equal to the RaycastHit.distance
Answer by canis · Jan 17, 2018 at 11:11 AM
@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.
Answer by Veltcrows · Jan 17, 2018 at 02:34 PM
Try this:
ball.position = hit.point + (ball.position - hit.point) * ball_radius;
Already tried that. The problem with that method is that it moves the ball from its X and Z position when it should not because that is controlled by another parameter.
It causes weird movement, it looks like the ball sticks to the edge ins$$anonymous$$d of just "laying" on it.