Advertisement
vikhik

Not quite working as intended...

May 23rd, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1.     def setDesiredVelocity(self, desiredVelocity):
  2.         self.desiredVelocity = desiredVelocity
  3.        
  4.     def update(self, bounds):        
  5.         self.modifyAcceleration()
  6.         self.velocity = Vector.vecadd(self.velocity, self.acceleration)
  7.         # self.rotation += self.angularMomentum
  8.         self.move(bounds)
  9.        
  10.     # Ft = m(v - u)
  11.     def modifyAcceleration(self):
  12.         force = Vector.vecsub(self.desiredVelocity, self.velocity)
  13.         force = [force[0]*self.mass, force[1]*self.mass]
  14.         self.applyForce(force)
  15.        
  16.     def applyForce(self, force):
  17.         magnitude = Vector.magnitude(force)
  18.         if magnitude > self.maxMagnitude:
  19.             force = [force[0]/magnitude*self.maxMagnitude, force[1]/magnitude*self.maxMagnitude]
  20.         accel = [force[0]/self.mass, force[1]/self.mass]
  21.         self.acceleration = Vector.vecadd(self.acceleration, accel)
  22.        
  23.     def move(self, bounds):
  24.         self.position = Vector.vecadd(self.position, self.velocity)
  25.         self.clamp(bounds)
  26.        
  27.     def clamp(self, bounds):
  28.         if bounds.contains(self.rect) == False:
  29.             self.rect.clamp_ip(bounds)
  30.             self.position = self.rect.center
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement