Inertia/Dampening of Movement

Hehe, I always feel compelled to prove I made at attempt to solve my problems before posting so…

…Searched the forums, studied the docs AND most importantly, I tried everything including a dangerous use of WHILE that of course hung the hell out of Unity. :smile:

Here is a snippet of my code (mind you it’s a modification of the Warehouse FPS code, so I use the term “mine” loosely):

…and as always, I’m not looking for someone to do the work for me, just point me in the right direction, though pseudo-code IS and always will be much appreciated.

Anyway I’m simply trying to include some inertia, so as you begin moving the character ‘accelerates’, and when you let go, ‘decelerates’. The code above actually works pretty well; movement now is not 0.0 or 1.0 but rather an interpolation between the two, great…

…but I tried setting it up so after you remove your finger, inertia would carry the player forward a small bit, rather than stop abruptly as it does now. I place some non-working code (including the aforementioned while loop gulp here:

…the code is gone now, but it too involved Mathf.SmoothDamp at one point, and a test to see if the values for lDiffVelocity* were != 0.0, and if so, do the dampening and blah blah, needless to say it doesn’t work.

Thoughts anyone? Am I at least on the right track with Mathf.SmoothDamp or am I misunderstanding it’s value? Is there a better way, perhaps more efficient?

Thanks guys! :smile:

Oh and though it’s iPhone code, it really is just general scripting that can be applied to non-iPhone Unity so…I made the call but if it’s still considered ‘iphone scripting’, I’ll know for next time. :smile: