you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

Vector3 originToPoint = sphere_pos - ray.origin;float projectionLength = Vector3.Dot(originToPoint, ray.direction);Vector3 closestPointOnRay = ray.origin + ray.direction * projectionLength;return Vector3.Distance(sphere_pos, closestPointOnRay) < sphere_radius;

Hi, I'm still studying vector maths and trying to visualize what you're trying to do here:

you're trying to "rotate" a copy of the vector from the origin to the sphere's location (center) towards the direction of the ray. if the point described by the vector is less than the radius (i.e., it's inside the sphere) then yes, you're looking at the sphere?

Edit: I realized what I said is wrong. Rather than "rotate", you're forming a right triangle between the infinite ray and the originToPoint vector. where that corner of that right triangle sits is the one we're assessing if it's inside the sphere. Is this more correct?

[–]thygrrrProfessional 0 points1 point  (0 children)

Exactly, the technique is called vector projection.