Search code examples
openai-gym

Changing the speed of a periodically appearing object in grid


I'm working in the minigrid environment. I currently have an object moving across the screen at one grid space per step count (from left to right). This object periodically appears currently half time on screen, and half off. I'd like to slow down the object so that it moves slower across the screen. I'm not sure how to do it without losing the periodic appearance attribute. Current code is below:

        idx = (self.step_count+2)%(2*self.width) # 2 is the ratio of appear not appear
        if idx < self.width:
            try:
                self.put_obj(self.obstacles[i_obst], idx , old_pos[1]) 
                self.grid.set(*old_pos, None) # deletes old  obstacle
            except:
                pass
        else:
            self.grid.set(*old_pos, None) # deletes old  obstacle  

Solution

  • I got something to work. The below snippet includes an integer titled "slow_factor" that reduces the speed yet still has the idx useful for the original purpose.

    idx = (self.step_count+2)//slow_factor%(2*self.width)