I’m making a big laser that uses CircleCast
to detect collision with objects. And I use LineRenderer
to render the laser, a ParticleSystem
to render the hit effect. The problem is, if I set the Line’s end point at the hit.point
from CircleCast
, the laser snaps to a weird angle that is not parallel with the gun’s direction.
How to get closest point between a collider and a ray/vector that doesn't intersect?
This point is called the “centroid”. It’s the center of the shape that was used to do the cast.
For 2D physics, it’s available simply as hit.centroid
.
For 3D physics, you need to manually calculate it using rayOrigin + normalizedRayDirection * hit.distance
.
© 2022 - 2024 — McMap. All rights reserved.
Thank you for the direction, I've figured it out Vector3 toTarget = Vector3.Project((Vector3)hit.point - transform.position, ShootDirection); hitPos = transform.position + toTarget;
– Evadnee