The animation is not working when it is called directly but when using keyboard cursor function the animation works perfectly and also the velocity is working. Plaes kindly refer the code