- Home /
Get closest point on collider on at a certain z depth
Ok so I've got a nice little 2.5D thing going on. My character can climb on obstacles and all, but currently I'm using the obstacles position and it's collider's extents (let's assume all obstacles have a box collider) to figure out what the character's new position on top of the obstacle should be. Now, this of course won't do if we rotate the obstacle along the y axis. I can't use extents because I don't know which axis to calculate (x or z, depending on how much it's rotated) and I can't use bounds.min.x because the minimum x of the collider might be on a different plane in the z depth than my character. My next thought is to raycast from the character to the obstacle but that seems a little like overkill. I'm thinking there must be a better way?
tl;dr: Given the following diagram, how do I figure out the position of the red dot?
You are overthinking this. Just use a raycast; it's not overkill, it's a great use case for it.
I can't use bounds.$$anonymous$$.x because the $$anonymous$$imum x of the collider might be on a different plane in the z depth than my character.
In which case, the amount of math you will need to do to figure it out (especially if it's a mesh collider on an irregular shape) will likely be more expensive than the raycast.
Your answer
Follow this Question
Related Questions
Can I use a raycast to retrieve information from the collider? 2 Answers
How would i find the center of an object with a Y axis offset to find the center on the top face? 1 Answer
Raycast: Different results depending on distance 1 Answer
raycasts only working with IsTrigger colliders? 1 Answer
Raycast, Linecast, sphere collider or capsule collider? 0 Answers