created js function to update player position