How would I do this better?

Hi I figured out how to do this on my own- but I am sure it is not the most elegant or efficient way. So I would like to see how more experienced python users would do this.

this is a 2d via 3d game a comedy/horror/action/puzzle game, basically this s a zombie moving from a grave to the waiting farmer where they fight- nothing big just simple random damage attacks. It works but now I’d like to see how it suppossed to be done. Especially the timing.

 # This task checks collission
        def vectorcheck(Task):
            
            pos = card_peasant_zombie_male.getX()  
            pos += -0.01625
            card_peasant_zombie_male.setX(pos)
            #lenVector = card_peasant_zombie_male.getPos() - card_farmer.getPos()
            textObject8.setText(str(pos))
            textObject9.setText(str(pos))
            if pos < 0.6:
                taskMgr.add(atktimer, 'MyTaskName')
                return Task.done
            return Task.again

        #combat!
        
        def atktimer(Task):
            if Task.time < 2.0:
                textObject9.setText(str(Task.time))            
                return Task.cont
            attack(self)
            return Task.done
        
        

        def attack(self):
            atk = random.randint(0,3)
            self.farmerhealth += -atk
            textObject8.setText(str(self.farmerhealth))
            textObject9.setText(str(self.zombiehealth))
            if self.farmerhealth < 0:
                card_farmer.removeNode()
                return
            defend(self)
                  
            
        def defend(self):
            atk = random.randint(0,3)
            self.zombiehealth += -atk
            textObject8.setText(str(self.zombiehealth))
            textObject9.setText(str(self.zombiehealth))            
            if self.zombiehealth < 0:
                card_peasant_zombie_male.removeNode()
                return
            attack(self)
            
            
        #zombies end here

        taskMgr.add(vectorcheck, 'vcheck')

Thanks JB SKaggs

Actually thats pretty neat. Never used tasks this way and maybe i should.

Maybe Task should be task because is a variable not a class.