For increasing speed I use (var) Speed += (var) acceleration; in void update, but when I release the keys with makes increasing the speed, the speed stops immediately, and this is not realistic. How can I do (when I release the input key) for make the object’ stop slowly?
Thank you.
The best option is to make your object a rigidbody that behaves under physics. You can now change your “speed” with “rigidbody.addforce” this will add a force that pushes the ridigbody. after you have left the key, the force will no longer be added to the rigidbody and it will slowly fade out. By adjusting the “mass” of the rigidbody u can choose if it should stop directly after leaving the key if the mass is high, or gettinger slower very slowly, if the mass is very low.