Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Simulates movement of an entity to point (x, y) assuming no collision
- def simulate(self, x, y, throttle):
- #Known bugs:
- #ZeroDivisionError when moving to position the entity is currently at
- #Used to negate distance and accelerate faster for entities with less mass
- coef = throttle / self.mass / pythagoras(self, (x, y))
- VX = self.vx + (x - self.x) * coef #Speed in x direction after applying thrust
- VY = self.vy + (y - self.y) * coef #Speed in y direction after applying thrust
- X = self.x + VX #X coordinate after moving
- Y = self.y + VY #Y coordinate after moving
- VXF = VX * (1-self.friction) #Speed in x direction after applying friction
- VYF = VY * (1-self.friction) #Speed in y direction after applying friction
- return (round(X), round(Y), round(VXF), round(VYF), VX, VY)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement