- Home /
Unity SphereCast - Getting the center of the last sphere before the hit
Hello, I'm new to Unity.
I'm working on a game that looks like bowling. My problem is about the Raycast. I'm trying to make a line for the ball to show it's path before the ball is thrown. Physics.Raycast won't give me accurate results because my ball has radius and Raycast doesn't. So I'm using SphereCast. The problem is I can't get the center of the latest Sphere before hitting a collider. With that center I can draw a line from my ball and this center.
I'm searching for this for a long time but couldn't find any answers.!
I put a photo to show the problem as I can. When I write hit.point, unity is giving me yellow position as it should but I want red position. alt text
Answer by Wolfgang_Brabaender · Dec 16, 2019 at 10:47 AM
A RaycastHit has the field "point" and "normal".
RaycastHit hit;
//do your Spherecast...
Vector3 center = hit.point + radius * hit.normal
Care: not tested ;) But this should work :)
hit.normal
is the normal of the surface, not the direction to the sphere that collided. In this example it works, but in any other the results are not what's expected.
Your answer
Follow this Question
Related Questions
How to identify multiple objects in a sphere cast? 1 Answer
Spherecast. Want to determine how close to the center of the sphere the collision occurred. 0 Answers
Manuals Sphere collison 0 Answers
Raycast Never Hits Anything?! 2 Answers
Physics.SphereCast with Vector3.Reflect returns weird results 1 Answer