I have a bat sprite trying to match the Y pos of the mouse.
Here is the basics:
#check if the mouse is above or below the bat
if bat.get_pos().y > mousePos.y:
game.direction = -1 #moving up
elif bat.get_pos().y < mousePos.y:
game.direction = 1 #moving down
game.direction = 0 #not moving
...here is moveBat()
func moveBat(delta, batspeed):
#get the bat's current position
var curPosition = bat.get_pos()
var newPosition = batspeed
#make the new position
if game.direction == -1:
newPosition = -batspeed
elif game.direction == 1:
newPosition = batspeed
#make the bat move in the correct direction
The functions work well. I move the mouse, the bat moves to meet the mouse at the speed I've set in batSpeed.
Often though, when the mouse is still (hand not on it, totally stationary), the bat will jitter for EXACTLY 3 pixels up and down outside of the range of the mouse's Y position. As though it's not quite sure which Y pixel it should be settled on.
Is there a way to smooth this out?