This works:
On a new solid, draw a path along the ceiling (just the surface where the ball will touch). Do the same for the floor on another solid.
Add a circle using the ellipse tool (this assumes you will have a uniform circle). Be sure to zero out the shape’s anchor point and position under “Contents” so it matches the layer anchor point.
Add three null objects. One will be the “Leader” that you animate on the x axis. The other two, “Top Tracer” and Bottom Tracer” will follow along the top and bottom paths when you paste this into the “position” parameter (change pathLayer so you have the correct paths selected):
pathLayer = thisComp.layer(“Bottom Path”)
pathToTrace = pathLayer(“ADBE Mask Parade”)(1)(“ADBE Mask Shape”);
startPos = pathLayer.toComp(pathToTrace.pointOnPath(0));
endPos = pathLayer.toComp(pathToTrace.pointOnPath(1));
pathWidth = endPos[0]-startPos[0];
leaderX = thisComp.layer(“Leader”).transform.position[0];
followOffset = 0-startPos[0];
pathUnits = 1/pathWidth;
progress = (leaderX*pathUnits)+(pathUnits*followOffset);
pathLayer.toComp(pathToTrace.pointOnPath(progress));
On your ball, use this for position:
topTracer = thisComp.layer(“Top Tracer”).transform.position;
bottomTracer = thisComp.layer(“Bottom Tracer”).transform.position;
vertPos = (topTracer[1]+bottomTracer[1])/2;
horizPos = thisComp.layer(“Leader”).transform.position[0];
[horizPos,vertPos];
And for the ball’s scale:
topTracer = thisComp.layer(“Top Tracer”).transform.position;
bottomTracer = thisComp.layer(“Bottom Tracer”).transform.position;
neededHeight = topTracer[1]-bottomTracer[1];
origHeight = content(“Ellipse 1”).content(“Ellipse Path 1”).size[1];
newHeight = (neededHeight/origHeight)*100;
[newHeight,newHeight];
Hope that helps!