Advertisement
Guest User

Untitled

a guest
Dec 21st, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. The inaccuracy will be due to accumulated rounding error. There will be a small amount of rounding error in your bullet's x and y velocities because we don't have infinite precision. Let's say there is an error of 0.1 pixels in the x speed. If you add that speed to a position 100 times, then the error will have grown to 100 * 0.1 = 10 pixels.
  2.  
  3. I think you have two options. You could just keep recalculating the speed every step. That will get rid of accumulated error.
  4.  
  5. Or you try to reduce the error at the begining. I suspect that the trigonometric functions are introducing some error for reasons I won't get into here. I would try using unit vectors instead.
  6.  
  7. (This code is based on some earlier code that you deleted.)
  8.  
  9. def getUnitVector(x1, y1, x2, y2):
  10. delx = x2 - x1
  11. dely = y2 - y1
  12. m = math.sqrt(delx * delx + dely * dely)
  13. unit = (delx / m, dely / m)
  14. return unit
  15.  
  16. aim = getUnitVector(startx, starty, mousex, mousey)
  17.  
  18. bx = BULLETSPEED * aim[0]
  19. by = BULLETSPEED * aim[1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement