Skip to content

Instantly share code, notes, and snippets.

@benjamingsmith
Last active August 29, 2015 13:56
Show Gist options
  • Save benjamingsmith/0555afffc0ef6d6f1da9 to your computer and use it in GitHub Desktop.
Save benjamingsmith/0555afffc0ef6d6f1da9 to your computer and use it in GitHub Desktop.
Smooth Heading
var currentHeading = 0;
var newHeading = 0;
var heading = 0;
var headingCatchSmooth = 0; //catch up smoothly to the heading value;
var headingCatchSmoothSlowly = 0;
function updateFeet(){
var diffAngle = heading - headingCatchSmooth;
//console.log("heading: "+ heading);
if (diffAngle < -180) diffAngle += 360;
if (diffAngle > 180) diffAngle -= 360;
//console.log("diffAngle: "+ diffAngle);
headingCatchSmooth += 0.02 * diffAngle;
diffAngle = headingCatchSmooth - headingCatchSmoothSlowly;
if (diffAngle < -180) diffAngle += 360;
if (diffAngle > 180) diffAngle -= 360;
headingCatchSmoothSlowly += 0.007 * diffAngle;
//console.log("headingCatchSmooth: "+ headingCatchSmooth);
//console.log("update feet: "+ heading);
var rotationString = "rotate("+String(headingCatchSmooth - headingCatchSmoothSlowly)+"deg)";
footprints.css({"-webkit-transform": rotationString});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment