Yes at this line of code
Code:
ball.setPosition((e.x-0.5)*3,e.y*3.5,3)
you have coded to always put the ball at z-coord 3 when moving the mouse. If you want to get the z-coord unaltered by the regular mouse movement you will have to change it to use the z-value from the ball's current position
Code:
pos = ball.getPosition() #get the current position
ball.setPosition((e.x-0.5)*3,e.y*3.5, pos[2] ) #pos[2] is the z-coord for the current position