Can anyone help me with a script that moves a child object along its local y axis to the parent objects ty of zero in the parent local space.
So not just grabbing the ty value and moving it up.
Note both the parent and child have differening rotational values
The same thing you would accomplish from grabbing its local axis in the viewport and sliding it along y until it aligns with the parents. So the channel box values of the child would all have to change.
I assume it needs worldMatrix calculations to achieve this.
Here is the result achieved in the viewport
to elaborate this is a kind of smart â€śsnap to groundâ€ť function that I will embed in a larger context of â€śdo this on everyframe the locator is below the parents tY0â€ť
Youâ€™re asking â€śWhere along the line of the Y axis of my object does it intersect the XY plane of its parent?â€ť. The google term is â€śLine Plane Intersectionâ€ť
Thereâ€™s a couple main ideas to make this possible:

If you make a line thatâ€™s perpendicular to the plane, then any other line thatâ€™s perpendicular to that line MUST be exactly on the plane.

The dot product of 2 vectors is 0 if and only if theyâ€™re perpendicular

If you have a point and a direction vector, that point plus some random multiple of the direction gives you a new point on a line.
Using those 3 ideas together: If we move some multiple of a direction from our starting point, and dot that with the normal, and it equals 0, then weâ€™re on the plane.
Using that we can make an equation, which we can directly solve for that â€śsome multipleâ€ť, which you can add to the Y translation to get to the plane.
I donâ€™t have time today to give you a FULL writeup â€¦ so I just googled it and found a Stack Overflow answer that seems worth trying 3D LinePlane Intersection  Stack Overflow
And just a little optimization you can do: the vector u
in the SO answer is equal to the second row of the matrix of your object divided by the Y scale value.
1 Like
Hi tfox_TD
Thank you for explaining the maths logic, and also knowing exactly what to call this term.
I have to admit this is more complicated than I first thought, and a little beyond my current coding skills (I am migrating from mel scripting to python slowly, but very keen to grow this skill)
If you have time Iâ€™d love to understand more how this can be written into a script to apply on a given selected locator and a plane.
my python wiz friend at work seems to think this can all be done with maya matrix maths (but I couldnt get his method to work)
You can quickly get a prototype using a variety of methods to approach a given problem. For example:
 A simple way to find the intersection of a ray with a plane (using elementary vector mathematics).
 Using the Maya API and the
closestIntersection
function
Both methods are discussed in detail here:
Intersection of a curve and a mesh  #8 by VVVSLAVA
Even if you donâ€™t use the closestIntersection
function, it still makes sense to use the Maya API. Because then you get highperformance tools for working with vectors and Maya matrices out of the box.
Using transformation matrices will certainly help you better understand the â€śkitchenâ€ť of any 3D application. But in the context of your problem, this is just an additional method.
To quickly get and set transformation matrices, you can use the command xform
with key matrix
with subkeys worldSpace
,absolute
, etc:
xform command
Also, if you were to describe the global goals that your code should fulfill, then perhaps a more efficient solution could be found using other methods.
1 Like
This is a great resource for understanding the plane equation and ray plan intersection works:
https://www.scratchapixel.com/lessons/3dbasicrendering/minimalraytracerrenderingsimpleshapes/rayplaneandraydiskintersection.html
If it looks a bit daunting donâ€™t worry, write down notes for what each notation stands for and look at it like a simple equation
1 Like