Confused about local, world coordinates when it comes to child objects...
OK. I got a cube. And the cube has a child cube. Cubey.
I also have a point on the surface of Cubey--and I need to know which face of Cubey that point is on.
That's not the problem--I figured out that if I compared the angles between the directional vectors from each of Cubey's faces to the point's vector then any angle less than 45 degrees means my surface point is on that side. For example:
If: Mathf.Abs(Vector3.Angle(surface_point,cubey.transform.right) is less than 45 degrees, my surface point is on the right side. If it's > 45 degrees, it's round the next corner. (Let's not get into edge cases).
This works fine. As long as Cubey shares the same position as his parent cube. Once Cubey moves away, things get inconsistent.
So--something to do with world vs local space I'm sure. But no matter what I do I can't figure out how to correct it. I've converted surface point to local but it doesn't fix it.
I guess the problem is I'm having a hard time getting my head around just where the vectors here are actually going. For instance--if I convert my surface point coordinates to Local space (in other words, relative to the the Parent) does that mean I'm ending up with a vector from the parent's 0,0,0 point through the point on Cubey? That doesn't sound like what I need. It seems like I'd want a line from Cubey's 0,0,0 point to the point on his surface, and then I'd want to get the angle between that vector and the one also starting from Cubey's 0,0,0 but aiming along his right-transform. How do I do that for a child object? Seems all the vectors stem either world origin or parent origin.
I've read a lot on it, but I feel like I still have some fundamental misunderstanding when it comes to child object geometry--I'm really hoping someone can shed some light...?
Your answer
Follow this Question
Related Questions
Find child coordinates and pass them further? 0 Answers
How do i reference the animator component of an active child gameobject from the parent? 0 Answers
Child object not rotating as parent 0 Answers
Getting position of a coordinate on the surface of a sphere 0 Answers
How to make child gameobject follow parent gameobject with rigidbody? 0 Answers