Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- I think you have two options. You could just keep recalculating the speed every step. That will get rid of accumulated error.
- 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.
- (This code is based on some earlier code that you deleted.)
- def getUnitVector(x1, y1, x2, y2):
- delx = x2 - x1
- dely = y2 - y1
- m = math.sqrt(delx * delx + dely * dely)
- unit = (delx / m, dely / m)
- return unit
- aim = getUnitVector(startx, starty, mousex, mousey)
- bx = BULLETSPEED * aim[0]
- by = BULLETSPEED * aim[1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement