[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Friction help




The acceleration is changed once a second (for meters/second) this
leads to very jumpy movement. I need to add a way to check how long it
takes the program to loop and multiply the acceleration by that much.
(I think)

A quick way, is to do something like this:

This allows you to define speed as in "pixels per second" or "rotation per second" or whatever. But this method is vulnerable to unstability if timesteps are not small enough. ( or change size too much)

def update(self): # Unit.update()
        # update movement
        new_loc = self.loc + self.vel * self.game.elapsed
        #...

def update(self): # Game.update()
        self.last = self.now
        self.now = pygame.time.get_ticks()
        self.elapsed = (self.now - self.last) / 1000.

--
Jake