This is my Pilot Kurt game:
https://kurtdekker.itch.io/pilotkurt
The above is a WebGL build, but check out how the throttle works with your mouse: that is exactly how it works on mobile touch with your fingers.
I did that with something I made called a VAButton, and you can get that in my ProximityButtons package (see below).
// read the power slider (a VAButton... see ProximityButtons repo below)
if (vab_power.fingerDown)
{
var vaby = vab_power.outputRaw.y;
// were you holding it previous frame?
if (engineFingerDown)
{
// actually adjust the power setting
power += (vaby - engineVabY);
power = Mathf.Clamp01(power);
}
// track previous for delta
engineVabY = vaby;
engineFingerDown = true;
}
else
{
engineFingerDown = false;
}
That’s it… when you place your finger nothing happens, but it instantly becomes “zero change” for sliding up or down from 0 to 1 power.
proximity_buttons is presently hosted at these locations:
https://bitbucket.org/kurtdekker/proximity_buttons
https://github.com/kurtdekker/proximity_buttons
https://gitlab.com/kurtdekker/proximity_buttons
https://sourceforge.net/projects/proximity-buttons/
This is the setup for a VAButton in Pilot Kurt, but there’s other examples in PRoximityButtons above:
// sz and sz2 are screen pixel dimensions of rect from my screen layout package
vab_power = gameObject.AddComponent<VAButton>();
vab_power.r_downable = new Rect( Screen.width - sz2, Screen.height - (sz + sz2), sz2, sz);
vab_power.label = "^\n^\npower\n^\n^";
vab_power.doClamp = true;
vab_power.doNormalize = false;
EDIT after seeing Grozz’ post above:
My controls do not have any intentional lag: you can slam from 0 to 1 instantly with the power lever.
If I wanted, I would use this pattern to introduce lag (engine momentum) AFTER the control intention is gathered, unchanged, the way it is above.
Smoothing movement between any two particular values:
https://discussions.unity.com/t/812925/5
You have currentQuantity and desiredQuantity.
- only set desiredQuantity
- the code always moves currentQuantity towards desiredQuantity
- read currentQuantity for the smoothed value
Works for floats, Vectors, Colors, Quaternions, anything continuous or lerp-able.
The code: https://gist.github.com/kurtdekker/fb3c33ec6911a1d9bfcb23e9f62adac4