Calculating spin of wheel w/ Xpresso 

Methods of Calculating rotation of wheel w/ Xpresso 

Firstly, i need to clarify that by no means is what I am trying to teach here the ‘right’ way to do this, infact, i'm pretty confident it's probably the wrong way to do this. for this reason i'd like to just mention a couple of other ways i have tried to calculate wheel spin in the hopes that you may look at this project and think about other more effective ways to get the same information with less steps… 

Method #1
  • Using a Memory node to find difference in position of the wheel from previous frame and range mapping this change to a rotational value that gets added to the current wheel rotation.
  • For this tutorial, this is the method I chose for various reasons including number of calculations and viewport responsiveness.

Method #2
  • Tracing the wheel position with a Mograph Tracer object, then using a spline node to find its length and map that into radial degree. This method became very a heavy calculation once 4 wheels are involved so i chose not to go with this option.


Setup Guide

This guide only illustrates a bare bones version of the full Xpresso setup i use on the main C4R rig for the simple reason that we are only working with one wheel here, and the wheel spin is the only part of this I wanted to look at for now. 

I chose to use the first method of calculation for reasons I described above, here is the completed Xpresso node tree for the final calculation broken down into the specific parts: 

STEP 1. Finding wheel diameter and calculate Wheel circumference

  • By finding the tire object's bounding box, we can extract just the vertical Y axis, which is essentially the diameter or 2x the radius. 
  • We then take the wheel diameter (Y output) and multiply by 2π to find Circumference.

STEP 2. Calculate the distance (or change) of the Wheel

  • output the Global Position of the base null and connect it to a memory node
  • The memory node will let us save the previous frames data of our Position input
  • connect both outputs to a distance node to calculate the difference, or change in position from previous frame to current frame.

STEP 3. Range map the distance traveled with the circumference to get the rotation change for the current frame.

  • By inputting the distance traveled and range mapping it to the circumference as the Input Upper, and 360˚ as the Output Upper, we effectively convert the change in distance to a change in rotational degrees.

STEP 4. Add change in rotation to current wheel rotation.

  • Using a simple Math:Add node, we find the current frame's rotation of the tire and add the the change in rotation to it.


Side Note:

Unfortunately I was never able to find a way to effectively and procedurally calculate the direction of the tires movement so that I could dynamically invert the spin of the wheel, this results in a reverse slide when the wheel moves in opposite directions.