Time for action – animating the rover
To animate the rover, perform the following steps:
1. Add several new fields to the
Fields
region of theRover
class to support wheel animation, as follows:Random rand = new Random(); private float wheelRotation = 0f; private float wheelBounceDelta = 0.01f; private int wheelBounceRange = 20; private float[] wheelBounceTargets = new float[4] {0f, 0f, 0f, 0f} ; private float[] wheelBounceCurrent = new float[4] { 0f, 0f, 0f, 0f }; private string[] wheelNames = new string[4] { "r_back_wheel_geo", "l_back_wheel_geo", "r_front_wheel_geo", "l_front_wheel_geo" };
2. Add the
Wheel Animation
region and theGenerateWheelTarget()
method to theRover
class as follows:#region Wheel Animation private void GenerateWheelTarget(int wheel) { float newBounceTarget = (float)rand.Next(0, wheelBounceRange+1); newBounceTarget -= wheelBounceRange / 2; wheelBounceTargets[wheel] = newBounceTarget / 100f; } #endregion
3. Add the
HasWheelReachedTarget...