change maxVelocity to maxVelocitySquared