I am trying to roll a 2D ball in 3D space that only moves on the x and y axis through a maze. I would like it to be rotating 360 degrees based on the curcumference so it looks like it is rolling no matter if it is moving along the x or y axis. I feel like it should be pretty straight forward to figure this out but I am at a loss.
The ball rolls through the maze in an expressive way not at a constant speed but always in a straight line. Not every keyframe is at a corner direction change which makes things more difficult. I am just starting to learn about expressions so much of this is not based on knowing just forum searching and through trial and error.
I have tried multiple variations on these three directions:
distance=position[0,1];
circumference=width*Math.PI;
distance/circumference*360;
This moves fine along the y axis or x axis.
(length(position,position.value_at_time(0)[0,1])/(width*Math.PI))*360
This works fine when moving on the y axis but the x axis rotates too slowly and then about 12 seconds in it stops completely and goes haywire after that.
ball = thisComp.layer("Ball").transform.position;
s1 = ball.velocityAtTime( time )[0];
s2 = ball.velocityAtTime( time )[1];
circumference=width*Math.PI;
if
(s1 > 1 || s1 < 1)
{
transform.position[0]/circumference*360;
}
if
(s2 > 1 || s2 < 1)
{
transform.position[0]/circumference*360;
}
I was hoping I could switch from x axis to y axis when it's velocity slows at every corner. Only rotates when moving along y axis.
I am not sure if it is possible or if there is a simple way that I don't know about (which is probably the case).
Thanks in advance