Last active
August 29, 2015 13:56
-
-
Save benjamingsmith/0555afffc0ef6d6f1da9 to your computer and use it in GitHub Desktop.
Smooth Heading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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