Last active
April 9, 2019 17:46
-
-
Save ainsleyrutterford/5e465bc8d1ab23697862cd43b54326e9 to your computer and use it in GitHub Desktop.
Simple linear interpolation function at a constant speed.
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
public float driverFloat; | |
public float currentFloat; | |
private float Interp(float current, float target, float divisor) { | |
if (target != current) { | |
return current + (target - current)/divisor; | |
} else { | |
return target; | |
} | |
} | |
void Update() { | |
if (isHandAttached) { | |
driverFloat = gameObject.GetComponent<LinearDrive>().linearMapping.value; | |
currentFloat = gameObject.GetComponent<LinearDrive>().linearMapping.value; | |
} else { | |
currentFloat = Interp(currentFloat, driverFloat, 10f); | |
gameObject.GetComponent<LinearDrive>().linearMapping.value = currentFloat; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment