Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def setDesiredVelocity(self, desiredVelocity):
- self.desiredVelocity = desiredVelocity
- def update(self, bounds):
- self.modifyAcceleration()
- self.velocity = Vector.vecadd(self.velocity, self.acceleration)
- # self.rotation += self.angularMomentum
- self.move(bounds)
- # Ft = m(v - u)
- def modifyAcceleration(self):
- force = Vector.vecsub(self.desiredVelocity, self.velocity)
- force = [force[0]*self.mass, force[1]*self.mass]
- self.applyForce(force)
- def applyForce(self, force):
- magnitude = Vector.magnitude(force)
- if magnitude > self.maxMagnitude:
- force = [force[0]/magnitude*self.maxMagnitude, force[1]/magnitude*self.maxMagnitude]
- accel = [force[0]/self.mass, force[1]/self.mass]
- self.acceleration = Vector.vecadd(self.acceleration, accel)
- def move(self, bounds):
- self.position = Vector.vecadd(self.position, self.velocity)
- self.clamp(bounds)
- def clamp(self, bounds):
- if bounds.contains(self.rect) == False:
- self.rect.clamp_ip(bounds)
- self.position = self.rect.center
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement