1 person found this helpful
You got lucky ; )
I bet your ball was just over 100px in diameter? Ideally about 115?
Your expression says: make my rotation equal my x position movement.
ball moves 360 pixels to the right = ball rotates 360 degrees clockwise.
For the ball to rotate without slipping or skidding it's circumference would need to equal the distance it moved.
Diameter = circumerefence / Pi = 360 / 3.14 = 114.6 pixels.
Your homework, should you choose to accept it...
make an expression that rolls without slipping or skidding for a ball of any size : )
2 people found this helpful
OK... to answer my own question : )
The key thing to note is that a pick-whipped expression basically just copies the values from one property to another - and those values are unitless. They are interpreted in terms of the units of the property to which they are applied. So in your case X pixels of movement is interpreted as X degrees of rotation.
You need to work out what proportion of a circle's circumference is the distance moved, which is:
distance / (Pi x diameter) . Having got the proportion, you can x 360 to calculate the degrees.
In expression speak:
dia = 300;
transform.position / (Math.PI * dia) * 360
1. Change the number 300 to whatever your circle diameter is.
2. No need to separate the dimensions. The '' at the end of transform.position says 'use the first ('X') value'.
Here is the site to learn all about expressions from the master:
Ha! You are correct, I got lucky... about 120px on the circle, now this is making sense!
And I will do my homework!