changed nextPosition to local instead of global variable in character