Skip to content

Instantly share code, notes, and snippets.

@ainsleyrutterford
Last active April 9, 2019 17:46
Show Gist options
  • Save ainsleyrutterford/5e465bc8d1ab23697862cd43b54326e9 to your computer and use it in GitHub Desktop.
Save ainsleyrutterford/5e465bc8d1ab23697862cd43b54326e9 to your computer and use it in GitHub Desktop.
Simple linear interpolation function at a constant speed.
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