- Home /
How do i get local Hit position of Raycast on a collider
HI, so I'm trying to build an AutoAim functionality for my Fps shooting game, The idea is that when user will point close to Enemy, it will automatically snap towards the center, for this purpose i put a collider in Enemy and detecting it with Raycast and a layer. I want to detect weather the Ray hitting the collider is on which side (Right or left) so that i can subtract the distance from midpoint and rotate my player's camera.
To Get position of RayHit i am using Hit.point , But issue is that it is returning value in WorldSpace, and value changes every time player moves.
alt text
Collider that I'm using to detect is always looking at camera and doesn't matter if i rotate around the enemy it will always be looking at camera
I want to get RayCastHit position on Collider not in worldspace
Answer by AbandonedCrypt · Feb 02, 2021 at 12:28 PM
Vector3 localHit = transform.InverseTransformPoint(hit.point);
Yup that definitely pushed me towards the right direction, I was using it before but not correctly, Then I read it deeply to know how it actually works. Thanks :)
Your answer
Follow this Question
Related Questions
RayCast2D problems on collision detection 3 Answers
Raycast exit point of collider 0 Answers
Raycasting not working on a procedural mesh with a mesh collider. 1 Answer
Raycast script help? 1 Answer