Please refer to this thread for how to post code nicely on the forums: Using code tags properly
Have you tried to put some ‘Debug.Log’ statements into your code to check the distance, if the ‘if statement’ executes, etc?
Have you checked that speed is not zero and that maxDistance is set appropriately?
Do you have any errors appearing in the console?