You canwill need to fix your update method and add some variables to your Bullet class and set them at the time of creating a Bullet like this:
# Bullet Class
class Bullet(pygame.sprite.Sprite):
def __init__(self, txvx, tyvy):
super().__init__()
self.image = pygame.Surface([4,10])
self.image.fill(red)
self.rect = self.image.get_rect()
self.target_xvelocity_x = txvx
self.target_yvelocity_y = tyvy
def update(self):
if self.rect.x >+= self.target_x:velocity_x
self.rect.xy -=+= bullet_speedself.velocity_y
# Spawning the Bullet
# 1. You need elifto self.rect.xdetermine <the self.target_x:
direction from the player to the crosshair
# X distance from player self.rect.xto +=crosshair
dx bullet_speed= (chx - hgrect.x)
# Y distance from player to crosshair
dy if= self.rect.y(chy >- selfhgrect.target_y:y)
# Direction from player to crosshair in radians
dir = math.atan2(dy, dx)
# self.rect2.y -=Calculate bullet_speed
a velocity vector with a given speed elifand self.rect.ythe <direction self.target_y:above
speed = 20 # units: pixels/update
vx = speed * math.cos(dir)
vy = self.rect.yspeed +=* bullet_speedmath.sin(dir)
# Then3. Create athe bullet likewith this
the calculated X and Y velocity
bullet = new Bullet(chxvx, chyvy)
```