- Home /
Raycasting to get an exact point on an object.
Hey guys! So I got a question about how to find a point on an object using raycasting. Now I know how to raycast to something and get the hit data but my problem is that I'm trying to get exactly where it hit in terms of the objects dimensions as I want to do certain actions depending on where on the cube the raycast hits. RaycastHit.point returns the point in world space which isnt what im looking for. So far I tried subtracting hit.point from the objects position but since the objects origin isnt in a corner it doesn't return an accurate representation of where on the cube I hit. I drew a picture to explain what I want to get more.
(3, 5) being the point I wish to try and get from the raycast.
Answer by Axelize · Feb 14, 2019 at 01:17 AM
Nevermind! I ended up solving it myself. So since I couldn't trust the origin of the object to give me accurate results. I grabbed the collider of the object the raycast hit and use the bounds min and max to figure out what specific area was hit.
Answer by JonPQ · Feb 14, 2019 at 12:39 AM
move your object's origin to the corner... or put a dummy empty object at the corner so you can subtract that position.
I want to avoid that if possible. All our assets are modular so that would mean having to do that for 100's of objects. I'm going to try and use the colliders height and width and figure it out with that. Not to sure if it will work so if anyone else has a solution that would be great!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
interesting raycast question 2 Answers
Collision point on surface? 1 Answer
Moving object with raycast issues 2 Answers
Find a point at a distance from point on a line passing through two points 1 Answer