- Home /
How to get closest point between a collider and a ray/vector that doesn't intersect?
I'm making a big laser that use 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 do I get the desired point from this?
Answer by Klarzahs · Oct 21, 2020 at 12:45 PM
Hi @cdr9042,
what you are looking for is called vector projection, have a look at this post at wikipedia.
Thank you for the direction, I've figured it out
Vector3 toTarget = Vector3.Project((Vector3)hit.point - transform.position, ShootDirection);
hitPos = transform.position + toTarget;
Your answer
Follow this Question
Related Questions
Machine Gun aim to crosshair 3 Answers
Raycast2D range never changes when it's defined. 0 Answers
Converting iPhone touch to world coordinates 1 Answer
getting graphics raycast hit position on UI element 0 Answers
Raycast at angles 1 Answer